From b776c51856e387941130562e3711005036ee26fb Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 14 Aug 2014 22:50:05 +0200 Subject: [i18n] Sanity checks, introduced subdir for template language files --- inc/dictionary.inc.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'inc/dictionary.inc.php') diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index 3a157555..5ac0d569 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -5,6 +5,8 @@ class Dictionary private static $messageArray; private static $languages; + private static $templateCache = array(); + private static $hardcodedMessages = false; public static function init() { @@ -53,7 +55,9 @@ class Dictionary { if ($lang === false) $lang = LANG; - $file = "lang/" . $lang . "/" . $template . ".json"; + $file = "lang/" . $lang . "/templates/" . $template . ".json"; + if (isset(self::$templateCache[$file])) + return self::$templateCache[$file]; $language = array('lang' => $lang); $content = @file_get_contents($file); if ($content === false) // File does not exist for language @@ -61,13 +65,16 @@ class Dictionary $json = json_decode($content, true); if (!is_array($json)) return $language; - return array_merge($language, $json); + return self::$templateCache[$file] = array_merge($language, $json); } public static function translate($string) { - $hardcoded = json_decode(file_get_contents("lang/" . LANG . "/messages-hardcoded.json"), true); - return $hardcoded[$string]; + if (self::$hardcodedMessages === false) + self::$hardcodedMessages = @json_decode(@file_get_contents("lang/" . LANG . "/messages-hardcoded.json"), true); + if (!isset(self::$hardcodedMessages[$string])) + return "(missing: $string :missing)"; + return self::$hardcodedMessages[$string]; } public static function getMessages() @@ -83,3 +90,4 @@ class Dictionary } Dictionary::init(); + -- cgit v1.2.3-55-g7522