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