You are here

function i18n_redirect_init in Internationalization 7

Implements hook_init()

File

i18n_redirect/i18n_redirect.module, line 26
Internationalization (i18n) module.

Code

function i18n_redirect_init() {
  $path = $_GET['q'];
  $language = i18n_language_interface();

  // Not for logged in users nor for home page
  if (!$path || drupal_is_front_page() || !empty($GLOBALS['user']->uid)) {
    return;
  }
  elseif ($translations = i18n_get_path_translations($path)) {
    if (isset($translations[$language->language]) && $translations[$language->language]['href'] != $path) {
      drupal_goto($translations[$language->language]['href'], array(
        'language' => $language,
      ), 301);
    }
  }
}