<?php

/**
 * @file
 * Internationalization (i18n) module.
 *
 * Redirect to language path when we have a translation for the current language.
 */

/**
 * Implements hook_init()
 */
function i18n_redirect_init() {
  $path = $_GET['q'];
  // Not for logged in users nor for home page
  if (!$path || drupal_is_front_page() || !empty($GLOBALS['user']->uid)) {
    return;
  }
  $language = i18n_language();
  foreach (module_implements('i18n_translate_path') as $module) {
    $translated = call_user_func($module . '_i18n_translate_path', $path, $language);
    if ($translated && $translated != $path) {
      drupal_goto($translated, array('language' => $language), 301);
    }
  }
}