From 2291f34155b806cf038b22d4f32620ce3cda9326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Fri, 15 Jun 2007 19:02:47 +0000 Subject: [PATCH] #151410 by myself: allow modules to watch for the exact strings used on a page --- modules/locale/locale.module | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 80351506b5b..d0ca4e743e5 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -282,22 +282,40 @@ function locale_theme() { * Provides interface translation services. * * This function is called from t() to translate a string if needed. + * + * @param $string + * A string to look up translation for. If omitted, all the + * cached strings will be returned in all languages already + * used on the page. + * @param $langcode + * Language code to use for the lookup. */ -function locale($string, $langcode = NULL) { +function locale($string = NULL, $langcode = NULL) { global $language; static $locale_t; + // Return all cached strings if no string was specified + if (!isset($string)) { + return $locale_t; + } + $langcode = isset($langcode) ? $langcode : $language->language; // Store database cached translations in a static var. if (!isset($locale_t[$langcode])) { $locale_t[$langcode] = array(); - if (!($cache = cache_get('locale:'. $langcode, 'cache'))) { - locale_refresh_cache(); - $cache = cache_get('locale:'. $langcode, 'cache'); - } - if ($cache) { - $locale_t[$langcode] = $cache->data; + // Disabling the usage of string caching allows a module to watch for + // the exact list of strings used on a page. From a performance + // perspective that is a really bad idea, so we have no user + // interface for this. Be careful when turning this option off! + if (variable_get('locale_cache_strings', 1) == 1) { + if (!($cache = cache_get('locale:'. $langcode, 'cache'))) { + locale_refresh_cache(); + $cache = cache_get('locale:'. $langcode, 'cache'); + } + if ($cache) { + $locale_t[$langcode] = $cache->data; + } } }