-
Notifications
You must be signed in to change notification settings - Fork 1
/
lang.php
41 lines (37 loc) · 1006 Bytes
/
lang.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
<?php
function userLanguage($baseUrl, $lang)
{
$file = $_SERVER['DOCUMENT_ROOT'].$baseUrl.'/locales/'. $lang . '.json';
if (!file_exists($file)) {
$file = $_SERVER['DOCUMENT_ROOT'].$baseUrl. '/locales/'.Flight::get('ini')['mainLanguage'].'.json';
}
return json_decode(file_get_contents($file), true);
}
function __($string)
{
$lang = getLang();
if (!Flight::has('i18n')) {
Flight::set('i18n', userLanguage(Flight::request()->base, $lang));
}
$translation = Flight::get('i18n');
if (isset($translation[$string])) {
return $translation[$string];
} else {
return $string;
}
}
function setLang($lang)
{
setcookie("extractLang", $lang, time()+31536000, '/');
Flight::set('lang', $lang);
}
function getLang()
{
if (!isset($_COOKIE["extractLang"])) {
setLang(Flight::get('ini')['mainLanguage']);
}
if (Flight::has('lang')) {
return Flight::get('lang');
}
return $_COOKIE["extractLang"];
}