mirror of
https://github.com/Mibew/mibew.git
synced 2025-04-24 07:24:44 +03:00
Remove "$messages" global variable
This commit is contained in:
parent
36b817ac58
commit
ae92fe1514
@ -150,14 +150,16 @@ function get_locale_links()
|
|||||||
/**
|
/**
|
||||||
* Load localized messages id some service locale info.
|
* 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.
|
* @param string $locale Name of a locale whose messages should be loaded.
|
||||||
|
* @return array Localized messages array
|
||||||
*/
|
*/
|
||||||
function load_messages($locale)
|
function load_messages($locale)
|
||||||
{
|
{
|
||||||
global $messages;
|
static $messages = array();
|
||||||
|
|
||||||
|
if (!isset($messages[$locale])) {
|
||||||
// Load core localization
|
// Load core localization
|
||||||
$locale_file = MIBEW_FS_ROOT . "/locales/{$locale}/properties";
|
$locale_file = MIBEW_FS_ROOT . "/locales/{$locale}/properties";
|
||||||
$locale_data = read_locale_file($locale_file);
|
$locale_data = read_locale_file($locale_file);
|
||||||
@ -192,6 +194,9 @@ function load_messages($locale)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $messages[$locale];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read and parse locale file.
|
* Read and parse locale file.
|
||||||
*
|
*
|
||||||
@ -229,12 +234,7 @@ function read_locale_file($path)
|
|||||||
|
|
||||||
function getstring_($text, $locale, $raw = false)
|
function getstring_($text, $locale, $raw = false)
|
||||||
{
|
{
|
||||||
global $messages;
|
$localized = load_messages($locale);
|
||||||
if (!isset($messages[$locale])) {
|
|
||||||
load_messages($locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
$localized = $messages[$locale];
|
|
||||||
if (isset($localized[$text])) {
|
if (isset($localized[$text])) {
|
||||||
return $raw
|
return $raw
|
||||||
? $localized[$text]
|
? $localized[$text]
|
||||||
@ -373,5 +373,3 @@ function save_message($locale, $key, $value)
|
|||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$messages = array();
|
|
||||||
|
@ -29,14 +29,8 @@ $source = verify_param("source", "/^[\w-]{2,5}$/", DEFAULT_LOCALE);
|
|||||||
$target = verify_param("target", "/^[\w-]{2,5}$/", CURRENT_LOCALE);
|
$target = verify_param("target", "/^[\w-]{2,5}$/", CURRENT_LOCALE);
|
||||||
$string_id = verify_param("key", "/^[_\.\w]+$/", "");
|
$string_id = verify_param("key", "/^[_\.\w]+$/", "");
|
||||||
|
|
||||||
if (!isset($messages[$source])) {
|
$lang1 = load_messages($source);
|
||||||
load_messages($source);
|
$lang2 = load_messages($target);
|
||||||
}
|
|
||||||
$lang1 = $messages[$source];
|
|
||||||
if (!isset($messages[$target])) {
|
|
||||||
load_messages($target);
|
|
||||||
}
|
|
||||||
$lang2 = $messages[$target];
|
|
||||||
|
|
||||||
$page = array(
|
$page = array(
|
||||||
'lang1' => $source,
|
'lang1' => $source,
|
||||||
|
Loading…
Reference in New Issue
Block a user