From fe7412bdaf02e00699fd6654f74838c4cbe38bf9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 15 Aug 2014 13:10:56 +0200 Subject: Find messages and hardcoded-messages in php files, fix editing of messages --- inc/dictionary.inc.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'inc/dictionary.inc.php') diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index 5ac0d569..14305c99 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -3,7 +3,7 @@ class Dictionary { - private static $messageArray; + private static $messageArray = array(); private static $languages; private static $templateCache = array(); private static $hardcodedMessages = false; @@ -48,14 +48,18 @@ class Dictionary } define('LANG', $language); - self::$messageArray = json_decode(file_get_contents("lang/" . LANG . "/messages.json"), true); } public static function getArrayTemplate($template, $lang = false) + { + return self::getArray('templates/' . $template, $lang); + } + + public static function getArray($section, $lang = false) { if ($lang === false) $lang = LANG; - $file = "lang/" . $lang . "/templates/" . $template . ".json"; + $file = Util::safePath("lang/" . $lang . "/" . $section . ".json"); if (isset(self::$templateCache[$file])) return self::$templateCache[$file]; $language = array('lang' => $lang); @@ -71,17 +75,25 @@ class Dictionary public static function translate($string) { if (self::$hardcodedMessages === false) - self::$hardcodedMessages = @json_decode(@file_get_contents("lang/" . LANG . "/messages-hardcoded.json"), true); + 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() + public static function getMessage($id) { - return self::$messageArray; + if (self::$messageArray === false) + self::$messageArray = json_decode(file_get_contents("lang/" . LANG . "/messages.json"), true); + if (!isset(self::$messageArray[$id])) + return "(missing: $id :missing)"; + return self::$messageArray[$id]; } + /** + * Get all supported languages as array + * @return array List of languages (2 char id) + */ public static function getLanguages() { return self::$languages; -- cgit v1.2.3-55-g7522