First version of the new public l10n API, with language context switching


$foo = array();
$foo['chuck'] = t3lib_l10n::localizeByKey('allPages');
$foo['norris'] = t3lib_l10n::localizeByKey('allPages', array('%pages' => 1, '%result' => 12), 1);
$foo['can-do-it-with-a-key'] = t3lib_l10n::localizeByKey('allPages');

$foo['but-with-a-string-too'] = t3lib_l10n::localize('all pages');

$foo['chuck-as-some-friend-in-spain'] = t3lib_l10n::localize('all pages');

$foo['back-to-us-home-sweet-home'] = t3lib_l10n::localize('all pages');


  1. Unitified API between the FE, BE and ExtJS (same logic, signature everywhere)
  2. Translate by key, ex: t3lib_l10n::localizeByKey('my.key')
  3. Translate by source string, ex: t3lib_l10n::localize('This is my string in english')
  4. Replacements (no sprintf anymore around the l10n API, it's include)
  5. Plural support
  6. Language Context Switching
  7. Complex alternative language stack
  8. l10n lazy file loading


Language Context Switching

If you need to send a mail to a user, who select "french" has communication language, but user your website in "english", you need to hack a bit the current API to retreive easly the "fr" language. Now you can just switch the language context and restore it just after.

Complex alternative language stack

In FE, actually the default fallback language if no label is localized in the current FE language is the english. With config.language_alt you can define only one new fallback language to have "current lang" -> "alt lang" -> "default, en".

In some case more complex fallback are need, like fr_CA -> fr_FR -> fr -> de -> default, en. We plan to add a new config.language.alt.stack options to setup this.

l10n lazy loading

Currently, the default language, the current language (and in FE context the alt lang) is always parsed and loaded in memory. For the feature "Complex alternative language stack", it's not possible to parse all the languages. So we implement a "lazy" loading the l10n file. So only used l10n file during the request is parsed/loaded

Updated by Dominique Feyer almost 11 years ago ยท 3 revisions