Translator
class Translator (View source)
A class for translating messages
Messages (labels) can be translated in two modes:
- by original label: untranslated label is used as a key
- by ID: string identifier is used as a key (eg. user.noaccess)
Correct plural form of translated message is returned when $quantity parameter is provided to a method. Otherwise, or on failure just translated version is returned (eg. when string is translated only to one form).
When all fails, untranslated (original) string or ID is returned (depends on translation method).
Placeholders' resolving is done when needed (see FormatResolver class).
Actual translating is done by injected TranslationProvider instance, so storage format depends on concrete implementation.
Properties
protected Service | $localizationService | ||
protected TranslationProviderInterface | $translationProvider | ||
protected FormatResolver | $formatResolver | ||
protected PluralsReader | $pluralsReader |
Methods
Translates the message given as $originalLabel.
Returns translated string found under the $labelId.
Details
void
injectLocalizationService(Service $localizationService)
No description
void
injectTranslationProvider(TranslationProviderInterface $translationProvider)
No description
void
injectFormatResolver(FormatResolver $formatResolver)
No description
void
injectPluralsReader(PluralsReader $pluralsReader)
No description
string
translateByOriginalLabel(string $originalLabel, array $arguments = [], mixed $quantity = null, Locale $locale = null, string $sourceName = 'Main', string $packageKey = 'Neos.Flow')
Translates the message given as $originalLabel.
Searches for a translation in the source as defined by $sourceName (interpretation depends on concrete translation provider used).
If any arguments are provided in the $arguments array, they will be inserted to the translated string (in place of corresponding placeholders, with format defined by these placeholders).
If $quantity is provided, correct plural form for provided $locale will be chosen and used to choose correct translation variant.
If no $locale is provided, default system locale will be used.
string|null
translateById(string $labelId, array $arguments = [], mixed $quantity = null, Locale $locale = null, string $sourceName = 'Main', string $packageKey = 'Neos.Flow')
Returns translated string found under the $labelId.
Searches for a translation in the source as defined by $sourceName (interpretation depends on concrete translation provider used).
If any arguments are provided in the $arguments array, they will be inserted to the translated string (in place of corresponding placeholders, with format defined by these placeholders).
If $quantity is provided, correct plural form for provided $locale will be chosen and used to choose correct translation variant.
protected string|null
getPluralForm(mixed $quantity, Locale $locale)
Get the plural form to be used.
If $quantity is numeric and non-NULL, the plural form for provided $locale will be chosen according to it.
In all other cases, NULL is returned.