From a3f667e586e73e996175477939aa7beb10630901 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 8 Jan 2015 14:50:21 +0100 Subject: Fix Minz_Translate::availableLanguages() method --- app/Models/ConfigurationSetter.php | 2 +- app/i18n/en/gen.php | 4 ++++ app/i18n/fr/gen.php | 4 ++++ app/views/configure/display.phtml | 4 ++-- lib/Minz/Translate.php | 28 +++++++++++++++++++++++++--- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php index e5ea6ff6f..f1c465c7c 100644 --- a/app/Models/ConfigurationSetter.php +++ b/app/Models/ConfigurationSetter.php @@ -89,7 +89,7 @@ class FreshRSS_ConfigurationSetter { private function _language(&$data, $value) { $value = strtolower($value); $languages = Minz_Translate::availableLanguages(); - if (!isset($languages[$value])) { + if (!in_array($value, $languages)) { $value = 'en'; } $data['language'] = $value; diff --git a/app/i18n/en/gen.php b/app/i18n/en/gen.php index b3b8d8647..6271717d4 100644 --- a/app/i18n/en/gen.php +++ b/app/i18n/en/gen.php @@ -100,6 +100,10 @@ return array( 'notif_title_new_articles' => 'FreshRSS: new articles!', 'should_be_activated' => 'JavaScript must be enabled', ), + 'lang' => array( + 'en' => 'English', + 'fr' => 'Français', + ), 'menu' => array( 'about' => 'About', 'admin' => 'Administration', diff --git a/app/i18n/fr/gen.php b/app/i18n/fr/gen.php index 996c81cf5..6b449484f 100644 --- a/app/i18n/fr/gen.php +++ b/app/i18n/fr/gen.php @@ -100,6 +100,10 @@ return array( 'notif_title_new_articles' => 'FreshRSS : nouveaux articles !', 'should_be_activated' => 'Le JavaScript doit être activé.', ), + 'lang' => array( + 'en' => 'English', + 'fr' => 'Français', + ), 'menu' => array( 'about' => 'À propos', 'admin' => 'Administration', diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 36a075ea7..02249bc55 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -11,8 +11,8 @@
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php index b05c9c695..d870b6bb2 100644 --- a/lib/Minz/Translate.php +++ b/lib/Minz/Translate.php @@ -9,6 +9,11 @@ * It uses files in `./app/i18n/` */ class Minz_Translate { + /** + * $path_list is the list of registered base path to search translations. + */ + private static $path_list = array(); + /** * $lang_name is the name of the current language to use. */ @@ -30,6 +35,7 @@ class Minz_Translate { */ public static function init($lang_name) { self::$lang_name = $lang_name; + self::$path_list = array(); self::$lang_files = array(); self::$translates = array(); self::registerPath(APP_PATH . '/i18n'); @@ -45,11 +51,21 @@ class Minz_Translate { /** * Return the list of available languages. - * @return an array. - * @todo fix this method. + * @return an array containing langs found in different registered paths. */ public static function availableLanguages() { - return array(); + $list_langs = array(); + + foreach (self::$path_list as $path) { + $path_langs = array_values(array_diff( + scandir($path), + array('..', '.') + )); + + $list_langs = array_merge($list_langs, $path_langs); + } + + return array_unique($list_langs); } /** @@ -58,6 +74,12 @@ class Minz_Translate { * @param $path a path containing i18n directories (e.g. ./en/, ./fr/). */ public static function registerPath($path) { + if (in_array($path, self::$path_list)) { + return; + } + + self::$path_list[] = $path; + // We load first i18n files for the current language. $lang_path = $path . '/' . self::$lang_name; $list_i18n_files = array_values(array_diff( -- cgit v1.2.3