### Eclipse Workspace Patch 1.0 #P drupal Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.640 diff -u -r1.640 common.inc --- includes/common.inc 4 May 2007 09:41:36 -0000 1.640 +++ includes/common.inc 15 May 2007 10:30:38 -0000 @@ -604,7 +604,7 @@ } /** - * Translate strings to the current locale. + * Translate strings. * * All human-readable text that will be displayed somewhere within a page should be * run through the t() function. @@ -695,27 +695,30 @@ * - @variable: escape plain text to HTML (check_plain) * - %variable: escape text and theme as a placeholder for user-submitted * content (check_plain + theme_placeholder) + * @param $t_language + * Language object for translating to a language other than current locale * @return * The translated string. */ -function t($string, $args = 0) { +function t($string, $args = 0, $langcode = NULL) { global $language; static $custom_strings; + $langcode = $langcode ? $langcode : $language->language; // First, check for an array of customized strings. If present, use the array // *instead of* database lookups. This is a high performance way to provide a // handful of string replacements. See settings.php for examples. // Cache the $custom_strings variable to improve performance. - if (!isset($custom_strings)) { - $custom_strings = variable_get('locale_custom_strings_'. $language->language, array()); + if (!isset($custom_strings[$langcode])) { + $custom_strings[$langcode] = variable_get('locale_custom_strings_'. $langcode, array()); } // Custom strings work for English too, even if locale module is disabled. - if (isset($custom_strings[$string])) { - $string = $custom_strings[$string]; + if (isset($custom_strings[$langcode][$string])) { + $string = $custom_strings[$langcode][$string]; } // Translate with locale module if enabled. - elseif (function_exists('locale') && $language->language != 'en') { - $string = locale($string); + elseif (function_exists('locale') && $langcode != 'en') { + $string = locale($string, $langcode); } if (!$args) { return $string; Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.171 diff -u -r1.171 locale.module --- modules/locale/locale.module 3 May 2007 09:51:08 -0000 1.171 +++ modules/locale/locale.module 15 May 2007 10:30:41 -0000 @@ -284,35 +284,36 @@ * * This function is called from t() to translate a string if needed. */ -function locale($string) { +function locale($string, $langcode = NULL) { global $language; static $locale_t; + $langcode = $langcode ? $langcode : $language->language; // Store database cached translations in a static var. - if (!isset($locale_t)) { - $locale_t = array(); - if (!($cache = cache_get('locale:'. $language->language, 'cache'))) { + if (!isset($locale_t[$langcode])) { + $locale_t[$langcode] = array(); + if (!($cache = cache_get('locale:'. $langcode, 'cache'))) { locale_refresh_cache(); - $cache = cache_get('locale:'. $language->language, 'cache'); + $cache = cache_get('locale:'. $langcode, 'cache'); } if ($cache) { - $locale_t = $cache->data; + $locale_t[$langcode] = $cache->data; } } // We have the translation cached (if it is TRUE, then there is no // translation, so there is no point in checking the database) - if (isset($locale_t[$string])) { - $string = ($locale_t[$string] === TRUE ? $string : $locale_t[$string]); + if (isset($locale_t[$langcode][$string])) { + $string = ($locale_t[$langcode][$string] === TRUE ? $string : $locale_t[$langcode][$string]); } // We do not have this translation cached, so get it from the DB. else { - $result = db_query("SELECT s.lid, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = '%s' AND t.language = '%s' AND s.textgroup = 'default'", $string, $language->language); + $result = db_query("SELECT s.lid, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = '%s' AND t.language = '%s' AND s.textgroup = 'default'", $string, $langcode); // Translation found if ($trans = db_fetch_object($result)) { if (!empty($trans->translation)) { - $locale_t[$string] = $trans->translation; + $locale_t[$langcode][$string] = $trans->translation; $string = $trans->translation; } } @@ -322,20 +323,20 @@ $result = db_query("SELECT lid, source FROM {locales_source} WHERE source = '%s' AND textgroup = 'default'", $string); // We have no such translation if ($obj = db_fetch_object($result)) { - if ($language) { - db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $obj->lid, $language->language); + if ($langcode) { + db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $obj->lid, $langcode); } } // We have no such source string else { db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', 'default')", request_uri(), $string); - if ($language) { + if ($langcode) { $lid = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = 'default'", $string)); - db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $lid->lid, $language->language); + db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $lid->lid, $langcode); } } // Clear locale cache in DB - cache_clear_all('locale:'. $language->language, 'cache'); + cache_clear_all('locale:'. $langcode, 'cache'); } }