Index: CHANGELOG.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/translatable/CHANGELOG.txt,v retrieving revision 1.1.2.13 diff -u -p -r1.1.2.13 CHANGELOG.txt --- CHANGELOG.txt 14 Apr 2008 03:12:45 -0000 1.1.2.13 +++ CHANGELOG.txt 16 Apr 2008 01:24:16 -0000 @@ -6,6 +6,7 @@ Translatable x.x-x.x, xxxx-xx-xx Translatable 5.x-1.x, xxxx-xx-xx -------------------------------- +#244780 by sun: Fixed switch by hostname and front page redirection support. #233403 by sun: Fixed fatal PHP error if i18n and Translatable are enabled concurrently. Minor code clean-up in language.inc. Index: includes/language.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/translatable/includes/language.inc,v retrieving revision 1.1.2.5 diff -u -p -r1.1.2.5 language.inc --- includes/language.inc 16 Apr 2008 01:17:02 -0000 1.1.2.5 +++ includes/language.inc 16 Apr 2008 01:22:40 -0000 @@ -16,7 +16,7 @@ * - browser language * - default locale * - * @see locale_initialize() + * @see locale_initialize(), translatable_change_uilocale() */ if (function_exists('i18n_get_lang')) { drupal_set_message(t('Translatable module must not be enabled concurrently with other multilingual modules. Please disable i18n and/or Localizer module(s) completely.'), 'error'); @@ -34,6 +34,9 @@ else { else if (variable_get('translatable_detect_browser', TRUE)) { translatable_set_locale(translatable_get_browser_lang()); } + else if (variable_get('translatable_switch_byhostname', FALSE)) { + translatable_set_locale(translatable_localebyhostname($_SERVER['HTTP_HOST'])); + } else { translatable_set_locale(translatable_get_default_locale()); } @@ -48,43 +51,43 @@ else { */ function translatable_change_uilocale() { $valid_locales = translatable_available_locales(); + $locale = translatable_get_locale(); - // Front page redirect. - // If the page is accessed by a search engine, the redirect is not applied. - if (variable_get('translatable_frontpage_redirect', TRUE) && drupal_is_front_page() && !isset($_SESSION['translatable_firstpageredirected'])) { + // Redirect to localized front page. + if (variable_get('translatable_frontpage_redirect', TRUE) && drupal_is_front_page()) { if (variable_get('translatable_switch_byhostname', FALSE)) { - $localebyhostname = translatable_localebyhostname($_SERVER['HTTP_HOST']); - if (translatable_get_locale() != $localebyhostname) { + if ($locale != translatable_localebyhostname($_SERVER['HTTP_HOST'])) { $url = 'http://'; - $url .= variable_get('translatable_switch_hostname_'. translatable_get_locale(), translatable_get_locale() .'.'. translatable_get_domain()); + $url .= variable_get('translatable_switch_hostname_'. $locale, $locale .'.'. translatable_get_domain()); $url .= base_path(); $url .= translatable_get_destination(); - $_SESSION['translatable_firstpageredirected'] = 1; drupal_goto($url); } } if (translatable_get_defaultcontentlocale() != translatable_node_get_contentlocale($_GET['q']) && translatable_node_existscontentlocale($_GET['q'], translatable_get_defaultcontentlocale())) { $destination = translatable_get_destination(); - $_SESSION['translatable_firstpageredirected'] = 1; drupal_goto($destination); } - $_SESSION['translatable_firstpageredirected'] = 1; return; } - // Switch by locale in hostname. + // Switch by hostname (reset locale). + // Since this check has been added to i18n_get_lang(), this code is actually + // executed if a user changes her locale in the user account settings only - + // with the effect of overriding a user's account setting. if (variable_get('translatable_switch_byhostname', FALSE)) { $localebyhostname = translatable_localebyhostname($_SERVER['HTTP_HOST']); - if (translatable_get_locale() != $localebyhostname) { + if ($locale != $localebyhostname) { translatable_set_locale($localebyhostname); drupal_goto(translatable_get_destination()); } + // End this function here. return; } // Switch by locale in query string. - if (variable_get('translatable_switch_byparameter', TRUE) && isset($_GET['locale']) && translatable_get_locale() != $_GET['locale']) { + if (variable_get('translatable_switch_byparameter', TRUE) && isset($_GET['locale']) && $locale != $_GET['locale']) { translatable_set_locale($_GET['locale']); drupal_goto(translatable_get_destination()); } @@ -95,7 +98,7 @@ function translatable_change_uilocale() return; } $pathlocale = translatable_node_get_contentlocale($_GET['q']); - if ($pathlocale && translatable_get_locale() != $pathlocale && array_key_exists($pathlocale, $valid_locales) && translatable_node_existscontentlocale($_GET['q'], translatable_get_locale())) { + if ($pathlocale && $locale != $pathlocale && isset($valid_locales[$pathlocale]) && translatable_node_existscontentlocale($_GET['q'], $locale)) { translatable_set_locale($pathlocale); drupal_goto($_GET['q']); } @@ -105,7 +108,7 @@ function translatable_change_uilocale() if (variable_get('translatable_switch_bylocaleprefix', TRUE)) { $localeinurl = explode('/', $_REQUEST['q']); $localeinurl = $localeinurl[0]; - if ((translatable_get_locale() != $localeinurl) && array_key_exists($localeinurl, $valid_locales)) { + if ($locale != $localeinurl && isset($valid_locales[$localeinurl])) { translatable_set_locale($localeinurl); drupal_goto($_GET['q']); } @@ -217,9 +220,8 @@ function translatable_get_locale() { */ function translatable_set_locale($_locale = '', $reload = FALSE) { global $locale; - if (translatable_validate_locale($_locale) && ($_locale != translatable_get_locale())) { - $locale = $_locale; - $_SESSION['current_locale'] = $locale; + if (translatable_validate_locale($_locale) && $_locale != $locale) { + $locale = $_SESSION['current_locale'] = $_locale; translatable_user_locale('adminlocale', $locale); } if ($reload) {