Fixed: i18n extensions: 'en' as fallback (#5426)

* Update Translate.php

* Small improvements

---------

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
This commit is contained in:
maTh
2023-05-28 18:02:04 +02:00
committed by GitHub
parent df80913747
commit eeefbdf9c7

View File

@@ -37,7 +37,7 @@ class Minz_Translate {
* Init the translation object.
* @param string $lang_name the lang to show.
*/
public static function init(?string $lang_name = null): void {
public static function init(string $lang_name = ''): void {
self::$lang_name = $lang_name;
self::$lang_files = array();
self::$translates = array();
@@ -125,9 +125,14 @@ class Minz_Translate {
*/
private static function loadLang(string $path): void {
$lang_path = $path . '/' . self::$lang_name;
if (!file_exists($lang_path) || self::$lang_name == '') {
// The lang path does not exist, nothing more to do.
return;
if (self::$lang_name === '' || !is_dir($lang_path)) {
// The lang path does not exist, fallback to English ('en')
self::$lang_name = 'en';
$lang_path = $path . '/' . self::$lang_name;
if (!is_dir($lang_path)) {
// English ('en') i18n files not provided. Stop here. The keys will be shown.
return;
}
}
$list_i18n_files = array_values(array_diff(