i18n_redirect.module 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) module.
  5. *
  6. * Redirect to language path when we have a translation for the current language.
  7. */
  8. /**
  9. * Implements hook_help().
  10. */
  11. function i18n_redirect_help($path, $arg) {
  12. switch ($path) {
  13. case 'admin/config/regional/i18n':
  14. if (!module_exists('i18n_node')) {
  15. $output = '<p>' . t('To have <em>Translation redirect</em> working with your content you should <a href="@admin_modules">enable the <em>Multilingual content</em> module</a>.', array('@admin_modules' => url('admin/modules'))) . '</p>';
  16. return $output;
  17. }
  18. }
  19. }
  20. /**
  21. * Implements hook_init()
  22. */
  23. function i18n_redirect_init() {
  24. $path = $_GET['q'];
  25. $language = i18n_language_interface();
  26. // Not for logged in users nor for home page
  27. if (!$path || drupal_is_front_page() || !empty($GLOBALS['user']->uid)) {
  28. return;
  29. }
  30. elseif ($translations = i18n_get_path_translations($path)) {
  31. if (isset($translations[$language->language]) && $translations[$language->language]['href'] != $path) {
  32. drupal_goto($translations[$language->language]['href'], array('language' => $language), 301);
  33. }
  34. }
  35. }