I10n

Translating extensions is often needed for frontend plugins. One challenge is to offer those translations for Javascript functions, another is to share translations between extensions, so that common labels are stored in one place. The Localization class tries to accomplish all those goals, while additionally offering a quick access to translations from fluid templates. Translations are to be stored in the common xliff files. If you want to share a global dictionary with all your extensions, rename any Resources\Private\Language\locallang.xlf.dist file to *.xlf and/or add more languages.

Retrieve a dictionary and assign it to the view

By default, the returns all translations from your current extension. You can pass an array of additional extension names you want to have included in your dictionary:

In your controller action:
...
$this->view->assign('dict', Localization::getDictionary());
...

In your fluid template:
...
{dict.subject}: {post.subject}
...

Use the dictionary in Javascript

If you want to have your translations available in Javascript as well, enable it by configuring xm_tools to do so (see Configuration). This will generate a Javascript file and make it load. Your translations are available in Javascript through:

...
xmTools.getTranslation('subject');
...

Use the dictionary in PHP

Of course you can also access your translations of the dictionary by using the Dictionary::getTranslations method or by accessing the translations directly via the magic Dictionary::__call method, e.g.:

...
$dictionary = Localization::getDictionary();
echo $dictionary->subject();
...