aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz/Translate.php
diff options
context:
space:
mode:
authorGravatar maTh <math-home@web.de> 2023-05-28 18:02:04 +0200
committerGravatar GitHub <noreply@github.com> 2023-05-28 18:02:04 +0200
commiteeefbdf9c720790b83cc82fd981929bf4d699120 (patch)
treefdcc417fc33b6dbc2850c3bc4aa15265db9249df /lib/Minz/Translate.php
parentdf80913747795e330af5c90e6d1b782b3d6d8f07 (diff)
Fixed: i18n extensions: 'en' as fallback (#5426)
* Update Translate.php * Small improvements --------- Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'lib/Minz/Translate.php')
-rw-r--r--lib/Minz/Translate.php13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index 87ae4a9ff..0c8810377 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -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(