--- i18n.module 2007-10-30 19:12:35.000000000 +0200 +++ i18n.module.php 2008-02-06 18:37:20.000000000 +0200 @@ -281,7 +286,21 @@ function i18n_admin_settings() { '#options' => array(t('Disabled'), t('Enabled' )), '#description' => t("User browser language for home page and links without language prefix."), ); - + // Language prefix + $form['prefix'] = array( + '#type' => 'fieldset', + '#title' => t('Language prefix'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#description' => t('Note: If you wish comparability with navigation mode (without language prefix), when module i18n is disabled, disable settings.'), + ); + $form['prefix']['i18n_prefix_default'] = array( + '#type' => 'radios', + '#title' => t('Language prefix for default language'), + '#default_value' => variable_get('i18n_prefix_default', 0), + '#options' => array(t('Disabled'), t('Enabled' )), + '#description' => t("Add a language prefix to Drupal paths when the current language is the default language. Some established sites or single language sites with default language is not English may wish to disable language prefix of Drupal paths when enabling i18n module."), + ); // Language icons $form['icons'] = array( '#type' => 'fieldset', @@ -502,20 +523,37 @@ function i18n_get_normal_path($path) { * Produces i18n paths, with language prefix * If path is empty or site frontpage, path = 'lang' * Check for frontpage and search for alias before adding language + * + * @param string $path + * Drupal Path + * @param string $lang + * Language prefix + * + * @return string + * Drupal path with language prefix. */ function i18n_path($path, $lang) { - if (!$path || $path == i18n_frontpage($lang)) { - return $lang; - } elseif($alias = drupal_lookup_path('alias', $path)) { - if($prefix = i18n_get_lang_prefix($alias)) { - // This alias will be valid only if it has the same language - return ($prefix == $lang) ? $alias : $lang.'/'.$path; - } else { // Alias without language prefix - return $lang.'/'.$alias; - } - } else { // Alias for language path will be searched later - return $lang.'/'.$path; - } + $temp = @trim($path, '/'); + $lang = ($lang = @trim($lang)) ? $lang : i18n_get_lang(); + $bool = (!variable_get('i18n_prefix_default', 0) && $cur_lang == $lang); + $def_lang = i18n_default_language(); + $frontpage = i18n_frontpage($lang); + if (!$path || $path == $frontpage || !$temp || $temp == $frontpage) { + $path = $bool ? i18n_url_rewrite('alias', $path, $path) : $lang; + $path = @trim($path, '/'); + return $path; + } + if(($alias = drupal_lookup_path('alias', $path))) { + if ($lang == i18n_get_lang_prefix($alias)) { + i18n_get_lang_prefix($alias, TRUE); // Alias without language prefix + } else { + $alias = i18n_url_rewrite('alias', $alias, $path); + } + $path = $alias; + } + $path = $bool ? $path : $lang .'/'. $path; + $path = @trim($path, '/'); + return $path; } /** @@ -699,25 +737,45 @@ if(!function_exists('custom_url_rewrite' function custom_url_rewrite($type, $path, $original) { return i18n_url_rewrite($type, $path, $original); } -} +} /** - * Rewrites path with current language and removes prefix if searching for source path + * Rewrites path with current language and removes + * prefix if searching for source path + * + * @param string $type + * @param string $path + * @param string $original + * + * @return string */ function i18n_url_rewrite($type, $path, $original){ - if ($type == 'alias' && !i18n_get_lang_prefix($path) ){ - return $path ? i18n_get_lang() . '/'. $path : i18n_get_lang(); - } elseif ($type == 'source') { + if ($type == 'alias') { + $def_lang = i18n_default_language(); + $cur_lang = i18n_get_lang(); + $pre_lang = i18n_get_lang_prefix($path, TRUE); + $bool = (!variable_get('i18n_prefix_default', 0) && $cur_lang == $def_lang); + if ($pre_lang) { + $path = ($pre_lang == $def_lang) + ? ($bool ? $path : $pre_lang .'/'. $path) + : ($pre_lang .'/'. $path); + } else { + $path = ($bool) + ? ($path) + : ($path ? $cur_lang . '/'. $path : $cur_lang); + } + $path = trim($path, '/'); + } + elseif ($type == 'source') { if ($path == $original) { - return i18n_get_normal_path($path); - } else { // Path may have been dealiased but still have language prefix - i18n_get_lang_prefix($path, TRUE); - return $path; + $path = i18n_get_normal_path($path); + } else { + // Path may have been dealiased but still have language prefix + i18n_get_lang_prefix($path, TRUE); } - } else { - return $path; } -} + return $path; +} /** * Implementation of hook_db_rewrite_sql()