TranslationInterface
interface TranslationInterface (View source)
Interface for the translation.manager translation service.
Methods
Translates a string to the current language or to a given language.
Translates a TranslatableMarkup object to a string.
Formats a string containing a count of items.
Details
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.
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: