PHP Класс 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.
См. также: FormatResolver
См. также: TranslationProvider\TranslationProviderInterface
См. также: Cldr\Reader\PluralsReader
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$formatResolver FormatResolver
$localizationService Service
$pluralsReader Neos\Flow\I18n\Cldr\Reader\PluralsReader
$translationProvider Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
getPluralForm ( mixed $quantity, Locale $locale ) : string Get the plural form to be used.

Описание методов

getPluralForm() защищенный Метод

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
Результат string

injectFormatResolver() публичный Метод

public injectFormatResolver ( FormatResolver $formatResolver ) : void
$formatResolver FormatResolver
Результат void

injectLocalizationService() публичный Метод

public injectLocalizationService ( Service $localizationService ) : void
$localizationService Service
Результат void

injectPluralsReader() публичный Метод

public injectPluralsReader ( PluralsReader $pluralsReader ) : void
$pluralsReader Neos\Flow\I18n\Cldr\Reader\PluralsReader
Результат void

injectTranslationProvider() публичный Метод

public injectTranslationProvider ( Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface $translationProvider ) : void
$translationProvider Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface
Результат void

translateById() публичный Метод

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.
См. также: 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
Результат string Translated message or NULL on failure

translateByOriginalLabel() публичный Метод

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
Результат string Translated $originalLabel or $originalLabel itself on failure

Описание свойств

$formatResolver защищенное свойство

protected FormatResolver,Neos\Flow\I18n $formatResolver
Результат FormatResolver

$localizationService защищенное свойство

protected Service,Neos\Flow\I18n $localizationService
Результат Service

$pluralsReader защищенное свойство

protected PluralsReader,Neos\Flow\I18n\Cldr\Reader $pluralsReader
Результат Neos\Flow\I18n\Cldr\Reader\PluralsReader

$translationProvider защищенное свойство

protected TranslationProviderInterface,Neos\Flow\I18n\TranslationProvider $translationProvider
Результат Neos\Flow\I18n\TranslationProvider\TranslationProviderInterface