Alexandre Alapetite 6 years ago committed by GitHub
parent 70bb228e1d
commit 32676d59a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      lib/Minz/Translate.php

@ -64,13 +64,17 @@ class Minz_Translate {
$list_langs = array(); $list_langs = array();
foreach (self::$path_list as $path) { foreach (self::$path_list as $path) {
$scan = scandir($path);
if (is_array($scan)) {
$path_langs = array_values(array_diff( $path_langs = array_values(array_diff(
scandir($path), $scan,
array('..', '.') array('..', '.')
)); ));
if (is_array($path_langs)) {
$list_langs = array_merge($list_langs, $path_langs); $list_langs = array_merge($list_langs, $path_langs);
} }
}
}
return array_unique($list_langs); return array_unique($list_langs);
} }
@ -80,13 +84,11 @@ class Minz_Translate {
* @param $path a path containing i18n directories (e.g. ./en/, ./fr/). * @param $path a path containing i18n directories (e.g. ./en/, ./fr/).
*/ */
public static function registerPath($path) { public static function registerPath($path) {
if (in_array($path, self::$path_list)) { if (!in_array($path, self::$path_list) && is_dir($path)) {
return;
}
self::$path_list[] = $path; self::$path_list[] = $path;
self::loadLang($path); self::loadLang($path);
} }
}
/** /**
* Load translations of the current language from the given path. * Load translations of the current language from the given path.
@ -94,7 +96,7 @@ class Minz_Translate {
*/ */
private static function loadLang($path) { private static function loadLang($path) {
$lang_path = $path . '/' . self::$lang_name; $lang_path = $path . '/' . self::$lang_name;
if (!file_exists($lang_path) || is_null(self::$lang_name)) { if (!file_exists($lang_path) || self::$lang_name == '') {
// The lang path does not exist, nothing more to do. // The lang path does not exist, nothing more to do.
return; return;
} }

Loading…
Cancel
Save