1 language.api.php hook_language_init()

Allows modules to act after language initialization has been performed.

This is primarily needed to provide translation for configuration variables in the proper bootstrap phase. Variables are user-defined strings and therefore should not be translated via t(), since the source string can change without notice and any previous translation would be lost. Moreover, since variables can be used in the bootstrap phase, we need a bootstrap hook to provide a translation early enough to avoid misalignments between code using the original values and code using the translated values. However modules implementing hook_boot() should be aware that language initialization did not happen yet and thus they cannot rely on translated variables.

Related topics

File

core/modules/system/language.api.php, line 25
Hooks provided by the base system for language support.

Code

function hook_language_init() {
  global $language, $settings;

  switch ($language->language) {
    case 'it':
      $settings['locale_custom_strings_en']['site_name'] = 'Il mio sito Backdrop';
      break;

    case 'fr':
      $settings['locale_custom_strings_en']['site_name'] = 'Mon site Backdrop';
      break;
  }
}