Issues 287 added to the default English language

- Modified file functions.inc.php - because if you add new language variable so it is necessary to immediately translate all languages or all files added to the English translation of which is very inconvenient and time consuming.

- Function psm_load_lang - loading the default language that I chose English and stored in the $ GLOBALS [ 'sm_lang_default'] for further use.

- Function psm_get_lang - edited selection of translation. If there is no translation in the language you chose the user returns to the default language.
pull/288/head
Pavel Dvořák 2016-05-15 19:24:37 +02:00
parent f01c39695d
commit 6ba2e6023b
1 changed files with 40 additions and 18 deletions

View File

@ -43,15 +43,24 @@ function psm_get_lang() {
if (empty($args)) return $GLOBALS['sm_lang'];
$result = null;
$resultDefault = null;
$node = null;
$nodeDefault = null;
if ($args) {
$node = '$GLOBALS[\'sm_lang\'][\'' . implode('\'][\'', $args) . '\']';
$nodeDefault = '$GLOBALS[\'sm_lang_default\'][\'' . implode('\'][\'', $args) . '\']';
}
eval('if (isset('.$node.')) $result = '.$node.';');
eval('if (isset(' . $node . ')) $result = ' . $node . ';');
eval('if (isset(' . $nodeDefault . ')) $resultDefault = ' . $nodeDefault . ';');
if (empty($result)) {
return $resultDefault;
} else {
return $result;
}
}
/**
* Load language from the language file to the $GLOBALS['sm_lang'] variable
@ -60,6 +69,19 @@ function psm_get_lang() {
* @see psm_get_lang()
*/
function psm_load_lang($lang) {
// if not in the language translation must always be available starting translation - English
$default_lang_file = PSM_PATH_LANG . 'en_US.lang.php';
if (file_exists($default_lang_file)) {
require $default_lang_file;
if (isset($sm_lang)) {
$GLOBALS['sm_lang_default'] = $sm_lang;
unset($sm_lang);
}
}
// translated language
$lang_file = PSM_PATH_LANG . $lang . '.lang.php';
if (!file_exists($lang_file)) {