From a39b3ec1bc695b2302eded54243b572ca6e04974 Mon Sep 17 00:00:00 2001 From: Jeroen Peelaerts Date: Sun, 4 Jul 2021 12:09:20 +0200 Subject: [PATCH] Fallback to english if translations are missing (#3205) --- application/core/MY_Lang.php | 11 +++++++++-- application/hooks/load_config.php | 25 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/application/core/MY_Lang.php b/application/core/MY_Lang.php index b04738367..d1fc59973 100644 --- a/application/core/MY_Lang.php +++ b/application/core/MY_Lang.php @@ -10,10 +10,17 @@ class MY_Lang extends CI_Lang $CI->config->set_item('language', $idiom); $loaded = $this->is_loaded; $this->is_loaded = array(); - + foreach($loaded as $file) { - $this->load(strtr($file, '', '_lang.php')); + $filename = strtr($file, '', '_lang.php'); + $this->load($filename, 'english'); + $array = $this->load($filename, $idiom, TRUE); + foreach($array as $lang_key => $lang_value) { + if ($lang_value != '') { + $this->language[$lang_key] = $lang_value; + } + } } } } diff --git a/application/hooks/load_config.php b/application/hooks/load_config.php index 1cb4b0ec5..07864906d 100644 --- a/application/hooks/load_config.php +++ b/application/hooks/load_config.php @@ -26,8 +26,8 @@ function load_config() $CI->config->set_item('language_code', 'en-US'); } - _load_language_files($CI, '../vendor/codeigniter/framework/system/language', current_language()); - _load_language_files($CI, '../application/language', current_language_code()); + _load_language_files($CI, '../vendor/codeigniter/framework/system/language', current_language(), FALSE); + _load_language_files($CI, '../application/language', current_language_code(), TRUE); //Set timezone from config database if($CI->config->item('timezone')) @@ -46,16 +46,33 @@ function load_config() * @param $CI * @param $path * @param $language + * @param $fallback */ -function _load_language_files($CI, $path, $language) +function _load_language_files($CI, $path, $language, $fallback) { $map = directory_map($path . DIRECTORY_SEPARATOR . $language); foreach($map as $file) { + if(!is_array($file) && substr(strrchr($file, '.'), 1) == 'php') { - $CI->lang->load(strtr($file, '', '_lang.php'), $language); + $filename = strtr($file, '', '_lang.php'); + if ($fallback) { + $CI->lang->load($filename, 'en-US'); + + $array = $CI->lang->load($filename, $language, TRUE); + foreach($array as $lang_key => $lang_value) { + if ($lang_value !== '') { + $CI->lang->language[$lang_key] = $lang_value; + } + } + } + else + { + $CI->lang->load($filename, $language); + } + } } }