### 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	12 May 2007 14:45:57 -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, $t_language = NULL) {
   global $language;
   static $custom_strings;
 
+  $t_language = $t_language ? $t_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[$t_language->language])) {
+    $custom_strings[$t_language->language] = variable_get('locale_custom_strings_'. $t_language->language, 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[$t_language->language][$string])) {
+    $string = $custom_strings[$t_language->language][$string];
   }
   // Translate with locale module if enabled.
-  elseif (function_exists('locale') && $language->language != 'en') {
-    $string = locale($string);
+  elseif (function_exists('locale') && $t_language->language != 'en') {
+    $string = locale($string, $t_language);
   }
   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	12 May 2007 14:45:57 -0000
@@ -284,35 +284,36 @@
  *
  * This function is called from t() to translate a string if needed.
  */
-function locale($string) {
+function locale($string, $t_language = NULL) {
   global $language;
   static $locale_t;
 
+  $t_language = $t_language ? $t_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[$t_language->language])) {
+    $locale_t[$t_language->language] = array();
+    if (!($cache = cache_get('locale:'. $t_language->language, 'cache'))) {
       locale_refresh_cache();
-      $cache = cache_get('locale:'. $language->language, 'cache');
+      $cache = cache_get('locale:'. $t_language->language, 'cache');
     }
     if ($cache) {
-      $locale_t = $cache->data;
+      $locale_t[$t_language->language] = $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[$t_language->language][$string])) {
+    $string = ($locale_t[$t_language->language][$string] === TRUE ? $string : $locale_t[$t_language->language][$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, $t_language->language);
     // Translation found
     if ($trans = db_fetch_object($result)) {
       if (!empty($trans->translation)) {
-        $locale_t[$string] = $trans->translation;
+        $locale_t[$t_language->language][$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 ($t_language) {
+          db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $obj->lid, $t_language->language);
         }
       }
       // 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 ($t_language) {
           $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, $t_language->language);
         }
       }
       // Clear locale cache in DB
-      cache_clear_all('locale:'. $language->language, 'cache');
+      cache_clear_all('locale:'. $t_language->language, 'cache');
     }
   }
 
