July 2017
Intermediate to advanced
456 pages
11h 32m
English
Like Drupal 7, there are still the t() and format_plural() functions. However, the functionality behind these relies on the TranslationManager class. This means that it can be dependency injected into any Drupal 8 services, controllers, plugins, and so on. This is the preferred mechanism for translating text in PHP, and many base plugin classes in Drupal already implement functions that delegate to the TranslationManager.
One thing to be aware of is that the mechanism that discovers translatable strings relies on the functions being called, named t() and formatPlural(). So, while the actual method to translate content is TranslationManager::translate(), the following will not be picked up by localize.drupal.org:
$this->stringTranslation->translate('Something'); ...Read now
Unlock full access