From 5cb1a901c3846fbce7943e64c3614f29ba9d5729 Mon Sep 17 00:00:00 2001 From: Focuslinkstech <45756999+Focuslinkstech@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:24:43 +0100 Subject: [PATCH] Language Switching customer can now choose preferred language from available language list. we are store language in session for now, if customer logout the language will reset back to default, we will move it to database in the coming update. --- init.php | 27 +++++++++++------ system/autoload/Lang.php | 7 ++++- system/boot.php | 1 + system/controllers/accounts.php | 25 +++++++++++++++- ui/ui/sections/user-header.tpl | 53 +++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 11 deletions(-) diff --git a/init.php b/init.php index e636d04d..c33acdfc 100644 --- a/init.php +++ b/init.php @@ -131,17 +131,26 @@ if ((!empty($radius_user) && $config['radius_enable']) || _post('radius_enable') } -if (empty($config['language'])) { - $config['language'] = 'english'; +// Check if the user has selected a language +if (!empty($_SESSION['user_language'])) { + $config['language'] = $_SESSION['user_language']; } -$lan_file = $root_path . File::pathFixer('system/lan/' . $config['language'] . '.json'); -if (file_exists($lan_file)) { - $_L = json_decode(file_get_contents($lan_file), true); - $_SESSION['Lang'] = $_L; + +if (empty($_SESSION['Lang'])) { + if (empty($config['language'])) { + $config['language'] = 'english'; + } + $lan_file = $root_path . File::pathFixer('system/lan/' . $config['language'] . '.json'); + if (file_exists($lan_file)) { + $_L = json_decode(file_get_contents($lan_file), true); + $_SESSION['Lang'] = $_L; + } else { + $_L['author'] = 'Auto Generated by iBNuX Script'; + $_SESSION['Lang'] = $_L; + file_put_contents($lan_file, json_encode($_L)); + } } else { - $_L['author'] = 'Auto Generated by iBNuX Script'; - $_SESSION['Lang'] = $_L; - file_put_contents($lan_file, json_encode($_L)); + $_L = $_SESSION['Lang']; } diff --git a/system/autoload/Lang.php b/system/autoload/Lang.php index c6328293..e037bf60 100644 --- a/system/autoload/Lang.php +++ b/system/autoload/Lang.php @@ -10,7 +10,12 @@ class Lang { public static function T($key) { - global $_L, $lan_file, $config; + global $_L, $lan_file, $root_path, $config; + + if (empty($lan_file)) { + $lan_file = $root_path . File::pathFixer('system/lan/' . $config['language'] . '.json'); + } + if (is_array($_SESSION['Lang'])) { $_L = array_merge($_L, $_SESSION['Lang']); } diff --git a/system/boot.php b/system/boot.php index 67101234..374a5b24 100644 --- a/system/boot.php +++ b/system/boot.php @@ -46,6 +46,7 @@ $ui->assign('_domain', str_replace('www.', '', parse_url(APP_URL, PHP_URL_HOST)) $ui->assign('_url', APP_URL . '/?_route='); $ui->assign('_path', __DIR__); $ui->assign('_c', $config); +$ui->assign('user_language', $_SESSION['user_language']); $ui->assign('UPLOAD_PATH', str_replace($root_path, '', $UPLOAD_PATH)); $ui->assign('CACHE_PATH', str_replace($root_path, '', $CACHE_PATH)); $ui->assign('PAGES_PATH', str_replace($root_path, '', $PAGES_PATH)); diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index 373cce22..fbf290f6 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -37,7 +37,7 @@ switch ($action) { } $user->password = $npass; $turs = ORM::for_table('tbl_user_recharges')->where('customer_id', $user['id'])->find_many(); - foreach($turs as $tur) { + foreach ($turs as $tur) { // if has active plan, change the password to devices if ($tur['status'] == 'on') { $p = ORM::for_table('tbl_plans')->where('id', $tur['plan_id'])->find_one(); @@ -239,6 +239,29 @@ switch ($action) { r2(U . 'accounts/profile', 's', Lang::T('Phone number updated successfully')); break; + case 'language-update-post': + global $root_path; + if (!empty($_POST['language'])) { + $selected_language = $_POST['language']; + + $_SESSION['user_language'] = $selected_language; + + $lan_file = $root_path . File::pathFixer('system/lan/' . $selected_language . '.json'); + + if (file_exists($lan_file)) { + $_L = json_decode(file_get_contents($lan_file), true); + $_SESSION['Lang'] = $_L; + } else { + $_L['author'] = 'Auto Generated by iBNuX Script'; + $_SESSION['Lang'] = $_L; + file_put_contents($lan_file, json_encode($_L)); + } + + r2($_SERVER['HTTP_REFERER'], 's', Lang::T('Languge set to ' . $selected_language)); + } + + break; + default: $ui->display('a404.tpl'); } diff --git a/ui/ui/sections/user-header.tpl b/ui/ui/sections/user-header.tpl index 367a390d..64ecf996 100644 --- a/ui/ui/sections/user-header.tpl +++ b/ui/ui/sections/user-header.tpl @@ -66,6 +66,15 @@ transform: rotate(360deg); } } + + .dropdown-menu .dropdown-item { + margin-bottom: 5px; + } + + .dropdown-menu .dropdown-item button { + margin: 0; + padding: 10px; + } {if isset($xheader)} @@ -87,6 +96,50 @@