tidy up, be more efficient and warn when language files are not found.

This commit is contained in:
Isaac Connor 2020-02-27 17:40:31 -05:00
parent d90177fb74
commit b3a8ac0b2a
1 changed files with 25 additions and 13 deletions

View File

@ -18,32 +18,44 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
function translate( $name ) {
function translate($name) {
global $SLANG;
if ( array_key_exists($name, $SLANG) )
// The isset is more performant
if ( isset($SLANG[$name]) || array_key_exists($name, $SLANG) )
return $SLANG[$name];
else
return $name;
}
function loadLanguage( $prefix='' ) {
function loadLanguage($prefix='') {
global $user;
if ( $prefix )
$prefix = $prefix.'/';
$fallbackLangFile = $prefix.'lang/en_gb.php';
$systemLangFile = $prefix.'lang/'.ZM_LANG_DEFAULT.'.php';
if ( isset($user['Language']) )
if ( isset($user['Language']) ) {
$userLangFile = $prefix.'lang/'.$user['Language'].'.php';
if ( isset($userLangFile) && file_exists($userLangFile) )
if ( file_exists($userLangFile) ) {
return $userLangFile;
elseif ( file_exists($systemLangFile) )
} else {
ZM\Warning("User language file $userLangFile does not exist.");
}
}
$systemLangFile = $prefix.'lang/'.ZM_LANG_DEFAULT.'.php';
if ( file_exists($systemLangFile) ) {
return $systemLangFile;
elseif ( file_exists($fallbackLangFile) )
} else {
ZM\Warning("System language file $systemLangFile does not exist.");
}
$fallbackLangFile = $prefix.'lang/en_gb.php';
if ( file_exists($fallbackLangFile) ) {
return $fallbackLangFile;
else
} else {
ZM\Error("Default language file $fallbackLangFile does not exist.");
}
return false;
}
@ -51,7 +63,7 @@ if ( $langFile = loadLanguage() ) {
require_once($langFile);
require_once('lang/default.php');
foreach ($DLANG as $key => $value) {
if ( ! array_key_exists($key, $SLANG) )
if ( ! (isset($SLANG[$key]) || array_key_exists($key, $SLANG)) )
$SLANG[$key] = $DLANG[$key];
}
}