summaryrefslogtreecommitdiff
path: root/includes
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 /includes
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 'includes')
-rw-r--r--includes/common.inc21
1 files changed, 13 insertions, 8 deletions
diff --git a/includes/common.inc b/includes/common.inc
index ec2f06432..feb28de30 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -604,7 +604,7 @@ function fix_gpc_magic() {
}
/**
- * Translate strings to the current locale.
+ * Translate strings to the page language or a given language.
*
* All human-readable text that will be displayed somewhere within a page should be
* run through the t() function.
@@ -695,27 +695,32 @@ function fix_gpc_magic() {
* - @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 $langcode
+ * Optional language code to translate to a language other than
+ * what is used to display the page.
* @return
* The translated string.
*/
-function t($string, $args = 0) {
+function t($string, $args = 0, $langcode = NULL) {
global $language;
static $custom_strings;
+ $langcode = isset($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;