PHP Class Neos\Flow\I18n\Translator

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.
See also: FormatResolver
See also: TranslationProvider\TranslationProviderInterface
See also: Cldr\Reader\PluralsReader
Exibir arquivo Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$formatResolver FormatResolver
$localizationService Service
$pluralsReader Neos\Flow\I18n\Cldr\Reader\PluralsReader
$translationProvider Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface

Public Methods

Method Description
injectFormatResolver ( FormatResolver $formatResolver ) : void
injectLocalizationService ( Service $localizationService ) : void
injectPluralsReader ( PluralsReader $pluralsReader ) : void
injectTranslationProvider ( Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface $translationProvider ) : void
translateById ( string $labelId, array $arguments = [], mixed $quantity = null, Locale $locale = null, string $sourceName = 'Main', string $packageKey = 'Neos.Flow' ) : string Returns translated string found under the $labelId.
translateByOriginalLabel ( string $originalLabel, array $arguments = [], mixed $quantity = null, Locale $locale = null, string $sourceName = 'Main', string $packageKey = 'Neos.Flow' ) : string Translates the message given as $originalLabel.

Protected Methods

Method Description
getPluralForm ( mixed $quantity, Locale $locale ) : string Get the plural form to be used.

Method Details

getPluralForm() protected method

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.
protected getPluralForm ( mixed $quantity, Locale $locale ) : string
$quantity mixed
$locale Locale
return string

injectFormatResolver() public method

public injectFormatResolver ( FormatResolver $formatResolver ) : void
$formatResolver FormatResolver
return void

injectLocalizationService() public method

public injectLocalizationService ( Service $localizationService ) : void
$localizationService Service
return void

injectPluralsReader() public method

public injectPluralsReader ( PluralsReader $pluralsReader ) : void
$pluralsReader Neos\Flow\I18n\Cldr\Reader\PluralsReader
return void

injectTranslationProvider() public method

public injectTranslationProvider ( Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface $translationProvider ) : void
$translationProvider Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface
return void

translateById() public method

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.
See also: Translator::translateByOriginalLabel()
public translateById ( string $labelId, array $arguments = [], mixed $quantity = null, Locale $locale = null, string $sourceName = 'Main', string $packageKey = 'Neos.Flow' ) : string
$labelId string Key to use for finding translation
$arguments array An array of values to replace placeholders with
$quantity mixed A number to find plural form for (float or int), NULL to not use plural forms
$locale Locale Locale to use (NULL for default one)
$sourceName string Name of file with translations, base path is $packageKey/Resources/Private/Locale/Translations/
$packageKey string Key of the package containing the source file
return string Translated message or NULL on failure

translateByOriginalLabel() public method

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.
public translateByOriginalLabel ( string $originalLabel, array $arguments = [], mixed $quantity = null, Locale $locale = null, string $sourceName = 'Main', string $packageKey = 'Neos.Flow' ) : string
$originalLabel string Untranslated message
$arguments array An array of values to replace placeholders with
$quantity mixed A number to find plural form for (float or int), NULL to not use plural forms
$locale Locale Locale to use (NULL for default one)
$sourceName string Name of file with translations, base path is $packageKey/Resources/Private/Locale/Translations/
$packageKey string Key of the package containing the source file
return string Translated $originalLabel or $originalLabel itself on failure

Property Details

$formatResolver protected_oe property

protected FormatResolver,Neos\Flow\I18n $formatResolver
return FormatResolver

$localizationService protected_oe property

protected Service,Neos\Flow\I18n $localizationService
return Service

$pluralsReader protected_oe property

protected PluralsReader,Neos\Flow\I18n\Cldr\Reader $pluralsReader
return Neos\Flow\I18n\Cldr\Reader\PluralsReader

$translationProvider protected_oe property

protected TranslationProviderInterface,Neos\Flow\I18n\TranslationProvider $translationProvider
return Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface