summaryrefslogtreecommitdiff
path: root/modules/locale
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-05-15 20:19:47 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-05-15 20:19:47 +0000
commit55b4cbadf2a9897e83ff9a9508f01d5a7caec848 (patch)
tree88feed859b418b050d3d9a40a97382978f948734 /modules/locale
parente80888ae258e854d5a9b29a411e4cc2983136bce (diff)
downloadbrdo-55b4cbadf2a9897e83ff9a9508f01d5a7caec848.tar.gz
brdo-55b4cbadf2a9897e83ff9a9508f01d5a7caec848.tar.bz2
#143249 by Jose A Reyero: add language parameter to t() to make it possible to retrieve translations of strings for different languages, to send emails to users in their own language for example
Diffstat (limited to 'modules/locale')
-rw-r--r--modules/locale/locale.module32
1 files changed, 17 insertions, 15 deletions
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index 8a8f03f3b..2bd65463e 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -284,35 +284,37 @@ function locale_theme() {
*
* 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 = isset($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 +324,20 @@ function locale($string) {
$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');
}
}