You are here

function admin_language_block_view in Administration Language 7

Implements hook_block_view().

File

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

Code

function admin_language_block_view($type) {
  $block = array();
  if ('admin_language_switcher' == $type && drupal_multilingual()) {
    $language_negotiation = variable_get('language_negotiation_language', array());
    if (!empty($language_negotiation['locale-url'])) {
      $path = drupal_is_front_page() ? '<front>' : current_path();
      $languages = language_list('enabled');
      $admin_language = variable_get('admin_language_default', 'en');
      $links = array();
      foreach ($languages[1] as $language) {
        if ($language->language != $admin_language) {
          $links[$language->language] = array(
            'href' => $path,
            'title' => $language->native,
            'language' => $language,
            'attributes' => array(
              'class' => array(
                'language-link',
              ),
            ),
          );
        }
      }

      // Modify links to point at translated versions when available.
      // same behavior as translation_translation_link_alter() but we don't
      // remove links when a translation is unavailable.
      if (module_exists('translation')) {
        if ($paths = translation_path_get_translations($path)) {
          $node = node_load(arg(1));
          $translations = translation_node_get_translations($node->tnid);
          foreach ($links as $langcode => $link) {
            if (isset($paths[$langcode]) && $translations[$langcode]->status) {

              // Translation in a different node.
              $links[$langcode]['href'] = $paths[$langcode];
            }
          }
        }
      }
      $block['subject'] = t('Languages');
      $block['content'] = theme('links', array(
        'links' => $links,
      ));
    }
  }
  return $block;
}