TranslationManager
class TranslationManager implements TranslationInterface, TranslatorInterface (View source)
Defines a chained translation implementation combining multiple translators.
Properties
| protected TranslatorInterface[][] | $translators | An unsorted array of arrays of active translators. |
|
| protected null|TranslatorInterface[] | $sortedTranslators | An array of translators, sorted by priority. |
|
| protected string | $defaultLangcode | The default langcode used in translations. |
Methods
Appends a translation system to the translation chain.
Sorts translators according to priority.
Retrieves English string to given language.
Translates a string to the current language or to a given language.
Translates a TranslatableMarkup object to a string.
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Sets the default langcode.
Resets translation cache.
Details
__construct(LanguageDefault $default_language)
Constructs a TranslationManager object.
$this
addTranslator(TranslatorInterface $translator, int $priority = 0)
Appends a translation system to the translation chain.
protected TranslatorInterface[]
sortTranslators()
Sorts translators according to priority.
string|false
getStringTranslation(string $langcode, string $string, string $context)
Retrieves English string to given language.
TranslatableMarkup
translate(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
Never call this translate() method directly. In order for strings to be localized, make them available in one of the ways supported by the
string
translateString(TranslatableMarkup $translated_string)
Translates a TranslatableMarkup object to a string.
protected string
doTranslate(string $string, array $options = [])
Translates a string to the current language or to a given language.
PluralTranslatableMarkup
formatPlural(int $count, string $singular, string $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
This function ensures that the string is pluralized correctly. Since TranslationInterface::translate() is called by this function, make sure not to pass already-localized strings to it. See PluralTranslatableMarkup::createFromTranslatedString() for that.
For example:
setDefaultLangcode(string $langcode)
Sets the default langcode.
reset()
Resets translation cache.
Since most translation systems implement some form of caching, this provides a way to delete that cache.