Remove "$messages" global variable

This commit is contained in:
Dmitriy Simushev 2014-05-23 11:41:06 +00:00
parent 36b817ac58
commit ae92fe1514
2 changed files with 35 additions and 43 deletions

View File

@ -150,14 +150,16 @@ function get_locale_links()
/**
* Load localized messages id some service locale info.
*
* @global array $messages Localized messages array
* Messages are statically cached.
*
* @param string $locale Name of a locale whose messages should be loaded.
* @return array Localized messages array
*/
function load_messages($locale)
{
global $messages;
static $messages = array();
if (!isset($messages[$locale])) {
// Load core localization
$locale_file = MIBEW_FS_ROOT . "/locales/{$locale}/properties";
$locale_data = read_locale_file($locale_file);
@ -192,6 +194,9 @@ function load_messages($locale)
}
}
return $messages[$locale];
}
/**
* Read and parse locale file.
*
@ -229,12 +234,7 @@ function read_locale_file($path)
function getstring_($text, $locale, $raw = false)
{
global $messages;
if (!isset($messages[$locale])) {
load_messages($locale);
}
$localized = $messages[$locale];
$localized = load_messages($locale);
if (isset($localized[$text])) {
return $raw
? $localized[$text]
@ -373,5 +373,3 @@ function save_message($locale, $key, $value)
fclose($fp);
}
}
$messages = array();

View File

@ -29,14 +29,8 @@ $source = verify_param("source", "/^[\w-]{2,5}$/", DEFAULT_LOCALE);
$target = verify_param("target", "/^[\w-]{2,5}$/", CURRENT_LOCALE);
$string_id = verify_param("key", "/^[_\.\w]+$/", "");
if (!isset($messages[$source])) {
load_messages($source);
}
$lang1 = $messages[$source];
if (!isset($messages[$target])) {
load_messages($target);
}
$lang2 = $messages[$target];
$lang1 = load_messages($source);
$lang2 = load_messages($target);
$page = array(
'lang1' => $source,