Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.278 diff -u -p -r1.278 bootstrap.inc --- includes/bootstrap.inc 30 Apr 2009 16:15:44 -0000 1.278 +++ includes/bootstrap.inc 3 May 2009 17:36:37 -0000 @@ -626,11 +626,33 @@ function variable_init($conf = array()) * The name of the variable to return. * @param $default * The default value to use if this variable has never been set. + * @param $langcode + * The language code to get the value for. Defaults to the code of the + * language used on the page, but then falls back to the global variable + * if a language specific is not found. Set it to empty to explicitly + * ask for a global variable. * @return * The value of the variable. */ -function variable_get($name, $default = NULL) { - global $conf; +function variable_get($name, $default = NULL, $langcode = NULL) { + global $conf, $language; + + // Before language_init, $language is empty. + if (!empty($language)) { + // If no language code, default to current language + if (!$langcode) { + $langcode = $language->language; + } + elseif (!isset($conf[$langcode])) { + // This will only happen when variable_get() is called with a language code. + // So it must be from a module, not during bootstrap. + $conf[$langcode] = language_variable_init($langcode); + } + if (isset($conf[$langcode][$name])) { + return $conf[$langcode][$name]; + } + } + return isset($conf[$name]) ? $conf[$name] : $default; } @@ -1317,7 +1339,7 @@ function drupal_get_bootstrap_phase() { } function _drupal_bootstrap($phase) { - global $conf, $user; + global $conf, $user, $language; switch ($phase) { @@ -1434,6 +1456,10 @@ function _drupal_bootstrap($phase) { case DRUPAL_BOOTSTRAP_FULL: require_once DRUPAL_ROOT . '/includes/common.inc'; _drupal_bootstrap_full(); + // Load variables for current language + if (function_exists('language_variable_init')) { + $conf[$language->language] = language_variable_init($language->language); + } break; } } Index: includes/language.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/language.inc,v retrieving revision 1.19 diff -u -p -r1.19 language.inc --- includes/language.inc 1 Feb 2009 16:45:53 -0000 1.19 +++ includes/language.inc 3 May 2009 17:36:37 -0000 @@ -142,3 +142,23 @@ function language_url_rewrite(&$path, &$ } } } + +/** + * Return array of localized variables from modules. + * + * This will only work after modules have been loaded, thus variables used + * before module loading won't be localized. + */ +function language_variable_init($langcode) { + if ((variable_get('language_count', 1) == 1)) { + return array(); + } + if ($cached = cache_get('variables:'.$langcode, 'cache')) { + $variables = $cached->data; + } + else { + $variables = module_invoke_all('variable_init', $langcode); + cache_set('variables:'.$langcode, $variables); + } + return $variables; +} \ No newline at end of file