You are here

function admin_language_language_init in Administration Language 7

Implements hook_language_init().

The module doesn't provide its own language negotiation provider to ensure it doesn't interfere with other language negotiation handlers, for example, the URL-based language negotiation which changes the request path if configured accordingly.

File

./admin_language.module, line 694
Makes admin pages be displayed in the administrator's preferred language.

Code

function admin_language_language_init() {
  global $language, $_admin_language;

  // We need the user module to check the access.
  drupal_load('module', 'user');
  $is_cli = drupal_is_cli() && variable_get('admin_language_force_cli', 0);
  if (user_access('display admin pages in another language') && drupal_multilingual() || $is_cli) {
    $languages = language_list('enabled');
    $languages = $languages[1];
    $admin_language = variable_get('admin_language_default', 'en');
    $_admin_language = $languages[$admin_language];
    if (_admin_language_switch_language() || $is_cli) {
      global $user;

      // user_load() can't be used here because it needs a higher bootstrap
      // level.
      $query = db_select('admin_language', 'al');
      $query
        ->addField('al', 'language');
      $query
        ->condition('uid', $user->uid);
      $usr_lang = $query
        ->execute()
        ->fetchField();
      if (isset($usr_lang)) {
        switch ($usr_lang) {
          case 'admin':

            // Nothing to do, use default value of $admin_language.
            break;
          case 'default':
            $default = language_default();
            $admin_language = $default->language;
            break;
          default:
            if (isset($languages[$usr_lang])) {
              $admin_language = $usr_lang;
            }
        }
      }
      $language = $languages[$admin_language];
    }
  }
  else {
    $_admin_language = $language;
  }
}