-
Notifications
You must be signed in to change notification settings - Fork 5
/
lang.php
40 lines (36 loc) · 1.02 KB
/
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
<?php
function userLanguage($baseUrl,$lang) {
$file = $_SERVER['DOCUMENT_ROOT'].$baseUrl.'/locales/'. $lang . '.json';
if(!file_exists($file))
{
$file = $_SERVER['DOCUMENT_ROOT'].$baseUrl. '/locales/it.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('it');
}
if(Flight::has('lang'))
return Flight::get('lang');
return $_COOKIE["extractLang"];
}
function checkLang() {
if (isset(Flight::request()->query['lang'])) {
setLang(substr(Flight::request()->query['lang'],0,2));
}
}
?>