You are here

function admin_language_user in Administration Language 6

Implementation of hook_user().

File

./admin_language.module, line 218
Makes sure all admin pages are displayed in the preferred language of the administrator.

Code

function admin_language_user($type, $edit, &$user, $category = NULL) {
  if (variable_get('language_count', 1) && ($type == 'register' && user_access('administer users') || $type == 'form' && $category == 'account' && user_access('display admin pages in another language'))) {
    $languages = language_list('enabled');
    $languages = $languages[1];
    $default = language_default();
    $admin_langcode = variable_get('admin_language', 'en');
    if (isset($languages[$admin_langcode])) {
      $lang = $languages[$admin_langcode];
      $admin_language_name = t($lang->name) . ($lang->native != t($lang->name) ? ' (' . $lang->native . ')' : '');
    }
    else {
      $admin_language_name = t('Not enabled');
    }
    $names = array(
      'admin' => t('Default administration language, currently !language', array(
        '!language' => $admin_language_name,
      )),
      'default' => t('Default site language, currently !language', array(
        '!language' => t($default->name) . ($default->native != t($default->name) ? ' (' . $default->native . ')' : ''),
      )),
    );
    if (user_access('use all enabled languages')) {
      foreach ($languages as $langcode => $item) {
        $name = t($item->name);
        $names[$langcode] = $name . ($item->native != $name ? ' (' . $item->native . ')' : '');
      }
    }
    $form['admin_language'] = array(
      '#type' => 'fieldset',
      '#title' => t('Administration language'),
    );
    $form['admin_language']['admin_language'] = array(
      '#type' => count($names) <= 5 ? 'radios' : 'select',
      '#title' => t('Default administration language'),
      '#default_value' => admin_language_preferred($user),
      '#options' => $names,
      '#description' => t('Select the default language to use for all administration pages. See the !settings-url for a list of affected pages.', array(
        '!settings-url' => l(t('administration language settings'), 'admin/settings/language/admin_language'),
      )),
    );
    return $form;
  }
}