class TranslationHelper implements ProtectedContextAwareInterface (View source)

Translation helpers for Eel contexts

Constants

I18N_LABEL_ID_PATTERN

Methods

string|null
translate(string $id, string $originalLabel = null, array $arguments = [], string $source = 'Main', string $package = null, mixed $quantity = null, string $locale = null)

Get the translated value for an id or original label

id(string $id)

Start collection of parameters for translation by id

value(string $value)

Start collection of parameters for translation by original label

bool
allowsCallOfMethod(string $methodName)

All methods are considered safe

string|null
translateByExplicitlyPassedOrderedArguments(string $id, string $originalLabel = null, array $arguments = [], string|null $source = 'Main', string $package = null, mixed $quantity = null, string $locale = null)

Get the translated value for an id or original label

string|null
translateByShortHandString(string $shortHandString)

Translate by shorthand string

createTranslationParameterToken(string $id = null, string $originalLabel = null)

Create and return a TranslationParameterToken.

Details

string|null translate(string $id, string $originalLabel = null, array $arguments = [], string $source = 'Main', string $package = null, mixed $quantity = null, string $locale = null)

Get the translated value for an id or original label

If only id is set and contains a translation shorthand string, translate according to that shorthand

In all other cases:

Replace all placeholders with corresponding values if they exist in the translated label.

Parameters

string $id

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

string $originalLabel

The original translation value (the untranslated source string).

array $arguments

Array of numerically indexed or named values to be inserted into placeholders. Have a look at the internationalization documentation in the definitive guide for details.

string $source

Name of file with translations

string $package

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

mixed $quantity

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

string $locale

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

Return Value

string|null

Translated label or source label / ID key

TranslationParameterToken id(string $id)

Start collection of parameters for translation by id

Parameters

string $id

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

Return Value

TranslationParameterToken

TranslationParameterToken value(string $value)

Start collection of parameters for translation by original label

Parameters

string $value

Return Value

TranslationParameterToken

bool allowsCallOfMethod(string $methodName)

All methods are considered safe

Parameters

string $methodName

Return Value

bool

protected string|null translateByExplicitlyPassedOrderedArguments(string $id, string $originalLabel = null, array $arguments = [], string|null $source = 'Main', string $package = null, mixed $quantity = null, string $locale = null)

Get the translated value for an id or original label

Replace all placeholders with corresponding values if they exist in the translated label.

Parameters

string $id

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

string $originalLabel

The original translation value (the untranslated source string).

array $arguments

Numerically indexed array of values to be inserted into placeholders

string|null $source

Name of file with translations, defaults to 'Main'

string $package

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

mixed $quantity

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

string $locale

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

Return Value

string|null

Translated label or source label / ID key

protected string|null translateByShortHandString(string $shortHandString)

Translate by shorthand string

Parameters

string $shortHandString (PackageKey:Source:trans-unit-id)

Return Value

string|null

Translated label or source label / ID key

Exceptions

InvalidArgumentException

protected TranslationParameterToken createTranslationParameterToken(string $id = null, string $originalLabel = null)

Create and return a TranslationParameterToken.

Parameters

string $id
string $originalLabel

Return Value

TranslationParameterToken