-
Notifications
You must be signed in to change notification settings - Fork 0
/
langfunc.php
92 lines (78 loc) · 1.88 KB
/
langfunc.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
include_once "config.php";
function getSupported($textArray)
{
if ($textArray===false)
{
return array();//no support
}
$rep = array();
//this is if you decide which languages are supported from the ABR_LANG array
//you can see/change this in config.php
if (SUPP_CHOICE=='arr')
{
foreach(ABR_LANG as $key => $value)
{
$rep[] = $key;
}
}
//this is if you decide which languages are supported from the language.xml file
//you can see/change this in config.php
elseif(SUPP_CHOICE=='file')
{
foreach($textArray['text'] as $elem)
{
foreach($elem as $lang => $texte)
{
if ($lang!='default' AND !in_array($lang, $rep))
{
$rep[] = $lang;
}
}
}
}
return $rep;
}
//sets the session, cookie language. The session must already be started
function setLang($supported)
{
//10 yrs
$cookieExpire = 10*365*24*3600;
if (isset($_GET['lang']) AND in_array($_GET['lang'], $supported))
{
$_SESSION['lang'] = $_GET['lang'];
setcookie('lang', $_GET['lang'], time() + $cookieExpire, null, null, false, true);
}
elseif (isset($_GET['from']) AND in_array($_GET['from'], $supported))
{
$_SESSION['lang'] = $_GET['from'];
setcookie('lang', $_GET['from'], time() + $cookieExpire, null, null, false, true);
}
elseif (isset($_SESSION['lang']))
{
//maybe it's the second time this function is called?
//no need to do anything
}
elseif (isset($_COOKIE['lang']))
{
$_SESSION['lang'] = $_COOKIE['lang'];
//pour réactualiser l'expiration du cookie?
//setcookie('lang', $_COOKIE['lang'], time() + $cookieExpire, null, null, false, true
}
else
{
$languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$lang = 'fr';
foreach($languages as $elem)
{
if (in_array($elem, $supported))
{
$lang = $elem;
break;
}
}
$_SESSION['lang'] = $lang;
setcookie('lang', $lang, time() + $cookieExpire, null, null, false, true);
}
}
?>