Skip to content

Commit

Permalink
Fixed: i18n extensions: 'en' as fallback (#5426)
Browse files Browse the repository at this point in the history
* Update Translate.php

* Small improvements

---------

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
  • Loading branch information
math-GH and Alkarex committed May 28, 2023
1 parent df80913 commit eeefbdf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Minz/Translate.php
Expand Up @@ -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();
Expand Down Expand Up @@ -125,9 +125,14 @@ public static function registerPath(string $path): void {
*/
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(
Expand Down

0 comments on commit eeefbdf

Please sign in to comment.