summaryrefslogtreecommitdiffstats
path: root/inc/dictionary.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-09-02 18:46:24 +0200
committerSimon Rettberg2014-09-02 18:46:24 +0200
commit32f22e10ff63a555e5b80207dc524390aa4bc6c1 (patch)
tree702a01c3ba1dc2a5ca6ebc4a7810005a8c76a16f /inc/dictionary.inc.php
parent[Render] Show untranslated tags in rendered output (diff)
downloadslx-admin-32f22e10ff63a555e5b80207dc524390aa4bc6c1.tar.gz
slx-admin-32f22e10ff63a555e5b80207dc524390aa4bc6c1.tar.xz
slx-admin-32f22e10ff63a555e5b80207dc524390aa4bc6c1.zip
[i18n] Language handling is now completely dynamic, no more hardcoded de,en,pt
Diffstat (limited to 'inc/dictionary.inc.php')
-rw-r--r--inc/dictionary.inc.php34
1 files changed, 26 insertions, 8 deletions
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php
index 6efd8fde..fc509112 100644
--- a/inc/dictionary.inc.php
+++ b/inc/dictionary.inc.php
@@ -4,7 +4,8 @@ class Dictionary
{
private static $messageArray = false;
- private static $languages;
+ private static $languages = false;
+ private static $languagesLong = false;
private static $stringCache = array();
private static $hardcodedMessages = false;
@@ -62,14 +63,13 @@ class Dictionary
$file = Util::safePath("lang/" . $lang . "/" . $section . ".json");
if (isset(self::$stringCache[$file]))
return self::$stringCache[$file];
- $language = array('lang' => $lang);
$content = @file_get_contents($file);
if ($content === false) // File does not exist for language
- return $language;
+ return array();
$json = json_decode($content, true);
if (!is_array($json))
- return $language;
- return self::$stringCache[$file] = array_merge($language, $json);
+ return array();
+ return self::$stringCache[$file] = $json;
}
public static function translate($section, $string = false)
@@ -100,11 +100,29 @@ class Dictionary
/**
* Get all supported languages as array
- * @return array List of languages (2 char id)
+ * @param boolean $withName true = return assoc array containinc cc and name of all languages;
+ * false = regular array containing only the ccs
+ * @return array List of languages
*/
- public static function getLanguages()
+ public static function getLanguages($withName = false)
{
- return self::$languages;
+ if (!$withName)
+ return self::$languages;
+ if (self::$languagesLong === false) {
+ self::$languagesLong = array();
+ foreach (self::$languages as $lang) {
+ if (file_exists("lang/$lang/name.txt")) {
+ $name = @file_get_contents("lang/$lang/name.txt");
+ } else {
+ $name = $lang;
+ }
+ self::$languagesLong[] = array(
+ 'cc' => $lang,
+ 'name' => $name
+ );
+ }
+ }
+ return self::$languagesLong;
}
}