From addcea9cd45a87f2ae56f879bad86425efc16fba Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 6 Jan 2015 21:10:51 +0100 Subject: Fix i18n loading and availableLanguages calls - Change the way to init i18n - Add a availableLanguages() method to Minz_Translate See https://github.com/FreshRSS/FreshRSS/issues/730 --- lib/Minz/Session.php | 2 +- lib/Minz/Translate.php | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'lib/Minz') diff --git a/lib/Minz/Session.php b/lib/Minz/Session.php index af4de75bb..cfe8debe9 100644 --- a/lib/Minz/Session.php +++ b/lib/Minz/Session.php @@ -55,7 +55,7 @@ class Minz_Session { if (!$force) { self::_param('language', $language); - Minz_Translate::reset(); + Minz_Translate::reset($language); } } diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php index 39200e81f..1b4102ca9 100644 --- a/lib/Minz/Translate.php +++ b/lib/Minz/Translate.php @@ -9,6 +9,11 @@ * It uses files in `./app/i18n/` */ class Minz_Translate { + /** + * $lang_list is the list of available languages. + */ + private static $lang_list = array(); + /** * $lang_name is the name of the current language to use. */ @@ -25,20 +30,30 @@ class Minz_Translate { private static $translates = array(); /** - * Load $lang_name and $lang_path based on configuration and selected language. + * Init the translation object. + * @param $lang_list the list of available languages. + * @param $lang_name the lang to show. */ - public static function init() { - $conf = Minz_Configuration::get('system'); - $l = $conf->language; - self::$lang_name = Minz_Session::param('language', $l); + public static function init($lang_list, $lang_name) { + self::$lang_list = $lang_list; + self::$lang_name = $lang_name; self::$lang_path = APP_PATH . '/i18n/' . self::$lang_name . '/'; } /** - * Alias for init(). + * Reset the translation object with a new language. + * @param $lang_name the new language to use + */ + public static function reset($lang_name) { + self::init(self::$lang_list, $lang_name); + } + + /** + * Return the list of available languages. + * @return an array. */ - public static function reset() { - self::init(); + public static function availableLanguages() { + return self::$lang_list; } /** -- cgit v1.2.3