diff options
author | Simon Rettberg | 2014-09-02 18:46:24 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-09-02 18:46:24 +0200 |
commit | 32f22e10ff63a555e5b80207dc524390aa4bc6c1 (patch) | |
tree | 702a01c3ba1dc2a5ca6ebc4a7810005a8c76a16f /inc | |
parent | [Render] Show untranslated tags in rendered output (diff) | |
download | slx-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')
-rw-r--r-- | inc/dictionary.inc.php | 34 | ||||
-rw-r--r-- | inc/menu.inc.php | 18 |
2 files changed, 26 insertions, 26 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; } } diff --git a/inc/menu.inc.php b/inc/menu.inc.php deleted file mode 100644 index fdec08c3..00000000 --- a/inc/menu.inc.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -require_once('inc/render.inc.php'); -require_once('inc/user.inc.php'); - -class Menu -{ - - public function loginPanel() - { - if (User::getName() === false) return Render::parse('menu-login'); - return Render::parse('menu-logout', array( - 'user' => User::getName() - )); - } - -} - |