Index: bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.172 diff -u -r1.172 bootstrap.inc --- bootstrap.inc 15 Jun 2007 06:45:05 -0000 1.172 +++ bootstrap.inc 1 Jul 2007 10:08:43 -0000 @@ -424,11 +424,32 @@ * 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) { - global $conf; +function variable_get($name, $default, $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; } @@ -861,7 +882,7 @@ } function _drupal_bootstrap($phase) { - global $conf; + global $conf, $language; switch ($phase) { @@ -921,6 +942,8 @@ case DRUPAL_BOOTSTRAP_FULL: require_once './includes/common.inc'; _drupal_bootstrap_full(); + // Load variables for default language + $conf[$language->language] = language_variable_init($language->language); break; } } @@ -1063,6 +1086,25 @@ return $property ? $language->$property : $language; } +/** + * 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; +} /** * If Drupal is behind a reverse proxy, we use the X-Forwarded-For header