Commit 2291f341 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

#151410 by myself: allow modules to watch for the exact strings used on a page

parent 85805096
......@@ -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;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment