-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_language.php
64 lines (51 loc) · 1.59 KB
/
set_language.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
$_lang = [];
$lang = '';
$langCookieSet = false;
if (isset($_GET['lang']) && $_GET['lang'] != '') {
$time = time() - 3600 * 24 * 365 * 10;
setcookie("lang", $_GET['lang'], ['path' => '/', 'samesite' => 'Lax', 'secure' => true]);
$time = time() + 3600 * 24 * 365 * 10;
setcookie("lang", $_GET['lang'], ['path' => '/', 'samesite' => 'Lax', 'secure' => true]);
$langCookieSet = true;
$lang = $_GET['lang'];
} elseif (isset($_COOKIE['lang']) && $_COOKIE['lang'] != '') {
$langCookieSet = true;
$lang = $_COOKIE['lang'];
} else {
if (isset($country_code) && $country_code != '') {
$lang = $languageCode;
}
}
$langfile = 'lang/' . strtolower($lang) . '.inc.php';
if (!file_exists($langfile)) {
$langfile = 'lang/en.inc.php';
$lang = 'EN';
}
$ogLocale = 'en_US';
if ($lang == 'CN') {
$ogLocale = 'zh_CN';
} elseif ($lang != 'EN') {
$ogLocale = strtolower($lang) . '_' . strtoupper($lang);
}
if (!$langCookieSet) {
$time = time() + 3600 * 24 * 365 * 10;
setcookie('lang', $lang, ['path' => '/', 'samesite' => 'Lax', 'secure' => true]);
}
include($langfile);
// loop around the $langfile and replace *## with <strong> and ##* with </strong>
foreach ($_lang as $key => $value) {
$_lang[$key] = str_replace("*## ", "<strong>", $value);
$_lang[$key] = str_replace(" ##*", "</strong>", $_lang[$key]);
}
$jsonLang = json_encode($_lang);
function TranslateText($text)
{
global $_lang;
if (isset($_lang[$text])) {
$translatedText = $_lang[$text];
} else {
$translatedText = $text;
}
return $translatedText;
}