class TranslationParameterToken implements ProtectedContextAwareInterface (View source)

Provides a chainable interface to collect all arguments needed to translate messages using source message or key ID

It also translates labels according to the configuration it stores

Properties

protected Translator $translator
protected array $parameters

Key/Value store to keep the collected parameters

Methods

__construct(string $id = null, string $value = null)

No description

injectTranslator(Translator $translator)

Inject the translator into the token.

id(string $id)

Set the id.

value(string $value)

Set the original translation value (the untranslated source string).

arguments(array $arguments)

Set the arguments.

source(string $source)

Set the source.

package(string $package)

Set the package.

quantity(mixed $quantity)

Set the quantity.

locale(string $locale)

Set the locale.

string|null
translate(array $overrides = [])

Translate according to currently collected parameters

string
__toString()

Runs translate to avoid the need of calling translate as a finishing method

bool
allowsCallOfMethod(string $methodName)

All methods are considered safe

Details

__construct(string $id = null, string $value = null)

No description

Parameters

string $id
string $value

injectTranslator(Translator $translator)

Inject the translator into the token.

Used for testing.

Parameters

Translator $translator

TranslationParameterToken id(string $id)

Set the id.

Parameters

string $id

Id to use for finding translation (trans-unit id in XLIFF)

Return Value

TranslationParameterToken

TranslationParameterToken value(string $value)

Set the original translation value (the untranslated source string).

Parameters

string $value

Return Value

TranslationParameterToken

TranslationParameterToken arguments(array $arguments)

Set the arguments.

Parameters

array $arguments

Numerically indexed array of values to be inserted into placeholders

Return Value

TranslationParameterToken

TranslationParameterToken source(string $source)

Set the source.

Parameters

string $source

Name of file with translations

Return Value

TranslationParameterToken

TranslationParameterToken package(string $package)

Set the package.

Parameters

string $package

Target package key. If not set, the current package key will be used

Return Value

TranslationParameterToken

TranslationParameterToken quantity(mixed $quantity)

Set the quantity.

Parameters

mixed $quantity

A number to find plural form for (float or int), NULL to not use plural forms

Return Value

TranslationParameterToken

TranslationParameterToken locale(string $locale)

Set the locale.

The locale Identifier will be converted into a Locale

Parameters

string $locale

An identifier of locale to use (NULL for use the default locale)

Return Value

TranslationParameterToken

Exceptions

Exception

string|null translate(array $overrides = [])

Translate according to currently collected parameters

Parameters

array $overrides

An associative array to override the collected parameters

Return Value

string|null

Exceptions

IndexOutOfBoundsException
InvalidFormatPlaceholderException

string __toString()

Runs translate to avoid the need of calling translate as a finishing method

Return Value

string

bool allowsCallOfMethod(string $methodName)

All methods are considered safe

Parameters

string $methodName

Return Value

bool