summaryrefslogtreecommitdiffstats
path: root/inc/dictionary.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-08-14 22:50:05 +0200
committerSimon Rettberg2014-08-14 22:50:05 +0200
commitb776c51856e387941130562e3711005036ee26fb (patch)
tree4cf8348e3ddaf1e783c4a86d3cf9cd847fa79217 /inc/dictionary.inc.php
parentRe-Format all language files for cleaner future diffs (diff)
downloadslx-admin-b776c51856e387941130562e3711005036ee26fb.tar.gz
slx-admin-b776c51856e387941130562e3711005036ee26fb.tar.xz
slx-admin-b776c51856e387941130562e3711005036ee26fb.zip
[i18n] Sanity checks, introduced subdir for template language files
Diffstat (limited to 'inc/dictionary.inc.php')
-rw-r--r--inc/dictionary.inc.php16
1 files changed, 12 insertions, 4 deletions
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();
+