From f0b273a9656faf9a523c670e08a7b633a294c3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Fri, 4 May 2007 08:32:00 +0000 Subject: #131061: Very fast t() for a small set of strings, by Moshe Weitzman, webernet, chx, erdemkose and myself --- includes/common.inc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'includes') diff --git a/includes/common.inc b/includes/common.inc index 07998d416..354eb4f7f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -700,7 +700,21 @@ function fix_gpc_magic() { */ function t($string, $args = 0) { global $language; - if (function_exists('locale') && $language->language != 'en') { + static $custom_strings; + + // 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()); + } + // Custom strings work for English too, even if locale module is disabled. + if (isset($custom_strings[$string])) { + $string = $custom_strings[$string]; + } + // Translate with locale module if enabled. + elseif (function_exists('locale') && $language->language != 'en') { $string = locale($string); } if (!$args) { -- cgit v1.2.3