summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-08 15:05:25 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-08 15:05:25 +0100
commit8f04cb9d9db90cce71a0de81bcfbc68b0873ea23 (patch)
tree7c2b827740de472f5131167f24592004b1abb7d1 /lib
parenta3f667e586e73e996175477939aa7beb10630901 (diff)
Change Minz_Translate::reset() behaviour
- Don't reset the path list (use init() instead) - init() accept a null lang_name. To use i18n, you'll have to use reset() later. It is helpful to load the list of available language before choosing one of them.
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Translate.php24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index d870b6bb2..a90af659e 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -33,7 +33,7 @@ class Minz_Translate {
* Init the translation object.
* @param $lang_name the lang to show.
*/
- public static function init($lang_name) {
+ public static function init($lang_name = null) {
self::$lang_name = $lang_name;
self::$path_list = array();
self::$lang_files = array();
@@ -46,7 +46,12 @@ class Minz_Translate {
* @param $lang_name the new language to use
*/
public static function reset($lang_name) {
- self::init($lang_name);
+ self::$lang_name = $lang_name;
+ self::$lang_files = array();
+ self::$translates = array();
+ foreach ($path_list as $path) {
+ self::loadLang($path);
+ }
}
/**
@@ -70,7 +75,6 @@ class Minz_Translate {
/**
* Register a new path and load i18n files inside.
- *
* @param $path a path containing i18n directories (e.g. ./en/, ./fr/).
*/
public static function registerPath($path) {
@@ -79,9 +83,20 @@ class Minz_Translate {
}
self::$path_list[] = $path;
+ self::loadLang($path);
+ }
- // We load first i18n files for the current language.
+ /**
+ * Load translations of the current language from the given path.
+ * @param $path the path containing i18n directories.
+ */
+ private static function loadLang($path) {
$lang_path = $path . '/' . self::$lang_name;
+ if (!file_exists($lang_path) || is_null(self::$lang_name)) {
+ // The lang path does not exist, nothing more to do.
+ return;
+ }
+
$list_i18n_files = array_values(array_diff(
scandir($lang_path),
array('..', '.')
@@ -102,7 +117,6 @@ class Minz_Translate {
/**
* Load the files associated to $key into $translates.
- *
* @param $key the top level i18n key we want to load.
*/
private static function loadKey($key) {