- fix errors if language files are broken

This commit is contained in:
Max Pozdeev 2022-04-15 18:41:46 +03:00
parent 4e083c6327
commit 5483b9a9e6
2 changed files with 9 additions and 0 deletions

View file

@ -54,6 +54,9 @@ class Lang
{
$this->code = $code;
$json = json_decode($jsonString, true);
if ($json === null) {
$json = array();
}
//load default language
if ( $code != $this->default ) {
@ -72,6 +75,9 @@ class Lang
}
$defStr = file_get_contents($this->langDir(). "{$this->default}.json");
$this->strings = json_decode($defStr, true);
if ($this->strings === null) {
die("Invalid JSON in default language file (". htmlspecialchars($this->default). ".json)");
}
}
function get($key)

View file

@ -153,6 +153,9 @@ function selectOptionsA($a, $key, $default=null)
$s = '';
if($default !== null && !isset($a[$key])) $key = $default;
foreach($a as $k=>$v) {
if (!is_array($v)) {
$v = array('name' => $k);
}
$s .= '<option value="'.htmlspecialchars($k).'" '.($k===$key?'selected="selected"':'').
(isset($v['title']) ? ' title="'.htmlspecialchars($v['title']).'"' : '').
'>'.htmlspecialchars($v['name']).'</option>';