diff --git a/CHANGELOG.txt b/CHANGELOG.txt index bb3019e0e5fb455817d8080f84b04811ba373342..4e1dd2ff0fe647685bb66893fb76115fee0946c1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,7 @@ -4-7-4 to .... +4-7-4 to 5-0 -------------- +- Added language session tracking +- Added per language menu items - Added support for RTL languages - Added native names for languages - Cleaned up multilingual variable management diff --git a/INSTALL.txt b/INSTALL.txt index b4d509e4beb5ecd0cc35cbdbbc8ebdc707b9a5cd..425ba05d2dfc32b44993d50ea9403cc6e23727f0 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -17,9 +17,7 @@ INSTALLATION: ============ 1. Create folder 'modules/i18n', and copy all the modules files, keeping directory structure, to this folder. - 2. If updating, run the update.php script following the standard procedure for Drupal updates. -3. If updating, run the update.php script following the standard procedure for Drupal updates. POST-INSTALLATION/CONFIGURATION: ============ diff --git a/i18n.module b/i18n.module index d0f5d9d36ae3209128e3518ed81d5c43fa649383..62f52ec74616eb7874eeb80ae476477aa12bd348 100644 --- a/i18n.module +++ b/i18n.module @@ -29,6 +29,7 @@ function i18n_get_lang($setlanguage = NULL) { return $i18n_language = _i18n_get_lang(); } } + /** * Minimum initialization */ @@ -58,7 +59,6 @@ function i18n_block($op = 'list', $delta = 0) { /** * Implementation of hook_init() * - * Complete initialization. Only when module enabled. * May do a redirect from home page for not to get wrong versions in cache * Warning: when in bootstrap mode, this may be called before i18n_get_lang() */ @@ -75,8 +75,8 @@ function i18n_init(){ // Check for update or cron scripts to disable rewriting and redirection if(preg_match('|/(?!index\.php)\w+\.php|', request_uri())){ i18n_selection_mode('off'); - } elseif( variable_get('cache', 0) && $lang != i18n_default_language() ) { - // Redirect to main page in $lang + } elseif ($lang != i18n_default_language()) { + // Redirect to main page in $lang when it's not default language. _i18n_goto($lang); } else { $_GET['q'] = i18n_frontpage($lang); @@ -88,7 +88,6 @@ function i18n_init(){ //search alias with and without lang and remove lang. $_GET['q'] = i18n_get_normal_path($path); } - // If not in bootstrap, variable init if(!_i18n_is_bootstrap()){ //include drupal_get_path('module', 'i18n').'/i18n.inc'; @@ -222,7 +221,7 @@ function i18n_admin_settings() { // Check languages $languages = variable_get('i18n_languages', array()); if (!count($languages) || ! count($languages['active']) > 1 ) { - drupal_set_message(t('No languages enabled. Visit the !locale_admin page to set up your languages.', array('%locale_admin' => l(t('Manage languages'), 'admin/settings/locale/'))), 'error'); + drupal_set_message(t('No languages enabled. Visit the !locale_admin page to set up your languages.', array('!locale_admin' => l(t('Manage languages'), 'admin/settings/locale/'))), 'error'); } $form['i18n_browser'] = array( '#type' => 'radios', @@ -336,8 +335,15 @@ function i18n_languages($key = 'active') { } } } else { - $languages = locale_supported_languages(); - $languages['site_default'] = key($languages); + // It is possible that languages are not initialized + if (function_exists('locale_supported_languages')) { + $languages = locale_supported_languages(); + } else { + // Worst case scenario: locale module not loaded, for cached pages, at least this won't break everything + unset($languages); // There's some PHP bug: http://www.zend.com/zend/week/week98.php + $languages['name'] = array('en' => 'English'); + } + $languages['site_default'] = key($languages['name']); $languages['active'] = $languages['name']; $languages['native'] = $languages['name']; } @@ -470,9 +476,10 @@ function i18n_get_links($path = '', $query = NULL) { * Gets language, checking in order: * * 1. Path language - * 2. User language - * 3. Browser language - * 4. Default language + * 2. Session language + * 3. User language + * 4. Browser language + * 5. Default language */ function _i18n_get_lang() { @@ -485,7 +492,11 @@ function _i18n_get_lang() { // Language not set, find one $languages = i18n_supported_languages(); if ($i18n_langpath && array_key_exists($i18n_langpath,$languages)) { - $i18n_lang = $i18n_langpath; + // Sets session language only when language is in path, not for other cases + $_SESSION['language'] = $i18n_lang = $i18n_langpath; + } + elseif (isset($_SESSION['language']) && array_key_exists($_SESSION['language'], $languages)) { + $i18n_lang = $_SESSION['language']; } elseif ($user->uid && $user->language && array_key_exists($user->language,$languages)) { $i18n_lang = $user->language; @@ -837,7 +848,6 @@ function i18n_perm() { */ function i18n_menu_edit_item_form_submit($form_id, $form_values) { $mid = menu_edit_item_save($form_values); - drupal_set_message("Saving item $mid with language =". $form_values['language']); db_query("UPDATE {menu} SET language = '%s' WHERE mid = %d", $form_values['language'], $mid); return 'admin/build/menu'; }