Display source language if no user language variable (#113)

* Display source language if no user language variable

* Fixes bug with dynamic language variables

https://github.com/torrentpier/torrentpier/pull/430

* undefined language variables fix

* Update sessions.php
This commit is contained in:
Roman Kelesidis 2023-04-01 23:24:26 +07:00 committed by GitHub
parent 0c3304594d
commit 147879df0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -568,7 +568,7 @@ class user_common
*/
function init_userprefs ()
{
global $bb_cfg, $theme, $lang, $DeltaTime;
global $bb_cfg, $theme, $source_lang, $DeltaTime;
if (defined('LANG_DIR')) return; // prevent multiple calling
@ -594,8 +594,17 @@ class user_common
if (!defined('LANG_DIR')) define('LANG_DIR', DEFAULT_LANG_DIR);
/** Temporary place source language to the global */
$lang = array();
require(ENGLISH_LANG_DIR .'main.php');
$source_lang = $lang;
unset($lang);
/** Place user language to the global */
global $lang;
require(LANG_DIR .'main.php');
setlocale(LC_ALL, isset($bb_cfg['lang'][$this->data['user_lang']]['locale']) ? $bb_cfg['lang'][$this->data['user_lang']]['locale'] : 'en_US.UTF-8');
$lang += $source_lang;
$theme = setup_style();
$DeltaTime = new Date_Delta();

View File

@ -245,10 +245,11 @@ class Template
{
$this->cur_tpl = $filename;
global $lang, $bb_cfg, $user, $tr_cfg;
global $lang, $source_lang, $bb_cfg, $user, $tr_cfg;
$L =& $lang;
$V =& $this->vars;
$SL =& $source_lang;
if ($filename)
{
@ -931,7 +932,7 @@ class Template
$code = str_replace($search, $replace, $code);
}
// This will handle the remaining root-level varrefs
$code = preg_replace('#\{(L_([a-z0-9\-_]+?))\}#i', '<?php echo isset($L[\'$2\']) ? $L[\'$2\'] : $V[\'$1\']; ?>', $code);
$code = preg_replace('#\{(L_([a-z0-9\-_]+?))\}#i', '<?php echo isset($L[\'$2\']) ? $L[\'$2\'] : (isset($SL[\'$2\']) ? $SL[\'$2\'] : $V[\'$1\']); ?>', $code);
$code = preg_replace('#\{(\$[a-z_][a-z0-9_$\->\'\"\.\[\]]*?)\}#i', '<?php echo isset($1) ? $1 : \'\'; ?>', $code);
$code = preg_replace('#\{(\#([a-z_][a-z0-9_]*?))\}#i', '<?php echo defined(\'$2\') ? $2 : \'\'; ?>', $code);
$code = preg_replace('#\{([a-z0-9\-_]+?)\}#i', '<?php echo isset($V[\'$1\']) ? $V[\'$1\'] : \'\'; ?>', $code);