Skip to content

Commit

Permalink
Merge pull request #408 from Exile37/bugfix/source-lang
Browse files Browse the repository at this point in the history
Display source language if no user language variable
  • Loading branch information
Exileum authored Jun 22, 2017
2 parents cbc2447 + 750d978 commit afebd74
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Helpers/CronHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public static function releaseDeadlock()
*/
public static function releaseLockFile()
{
rename(CRON_RUNNING, CRON_ALLOWED);
if (file_exists(CRON_RUNNING)) {
rename(CRON_RUNNING, CRON_ALLOWED);
}
self::touchLockFile(CRON_ALLOWED);
}

Expand Down
12 changes: 10 additions & 2 deletions src/Legacy/Common/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,14 @@ public function set_shortcuts()
*/
public function init_userprefs()
{
global $bb_cfg, $theme, $lang, $DeltaTime;
global $bb_cfg, $theme, $source_lang, $DeltaTime;

if (defined('LANG_DIR')) {
return;
} // prevent multiple calling

define('DEFAULT_LANG_DIR', LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/');
define('ENGLISH_LANG_DIR', LANG_ROOT_DIR . '/en/');
define('SOURCE_LANG_DIR', LANG_ROOT_DIR . '/source/');

if ($this->data['user_id'] != GUEST_UID) {
if ($this->data['user_lang'] && $this->data['user_lang'] != $bb_cfg['default_lang']) {
Expand All @@ -598,6 +598,14 @@ public function init_userprefs()
define('LANG_DIR', DEFAULT_LANG_DIR);
}

/** Temporary place source language to the global */
$lang = [];
require(SOURCE_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');
Expand Down
5 changes: 3 additions & 2 deletions src/Legacy/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,11 @@ public function execute($filename, $code, $handle)
{
$this->cur_tpl = $filename;

global $lang, $bb_cfg, $user;
global $lang, $source_lang, $bb_cfg, $user;

$L =& $lang;
$V =& $this->vars;
$SL =& $source_lang;

if ($filename) {
include $filename;
Expand Down Expand Up @@ -773,7 +774,7 @@ public function _compile_text($code)
$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\'] : \'$2\'); ?>', $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);
Expand Down

0 comments on commit afebd74

Please sign in to comment.