-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinclude_langdetect.php
98 lines (69 loc) · 1.93 KB
/
include_langdetect.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
93
94
95
96
97
98
<?
// 1. pt_br
// 2. pt_pt
// 3. es_mx
// 4. es_sp
$uri = $_SERVER["REQUEST_URI"];
ereg("/([a-z_a-z]{5})", $uri, $regs);
$newlang = $regs[1];
if ($newlang) {
if (($newlang!="pt_br")&&($newlang!="pt_pt")&&($newlang!="sp_mx")&&($newlang!="sp_sp")) {
$global_lang = "pt_br";
} else {
// Language set by cookie
$global_lang = $newlang;
}
} else {
// Language Detection
$langs = array();
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
if (count($lang_parse[1])) {
$langs = array_combine($lang_parse[1], $lang_parse[4]);
foreach ($langs as $lang => $val) {
if ($val === '') $langs[$lang] = 1;
}
arsort($langs, SORT_NUMERIC);
}
}
if ($langs[0]=="pt-br") {
// Brazil
$global_lang = "pt_br";
} else {
$detect = 0;
switch ($langs[0]) {
case "es-mx": $global_lang = "sp_mx"; break;
case "es-sp": $global_lang = "sp_sp"; break;
case "es": $detect = 1; break;
case "pt": $detect = 1; break;
default: $detect = 1; break;
}
if ($detect==1) {
include("include_ip2c.php");
$ip2c=new ip2country();
$ipcountry = $ip2c->get_country_code();
if ($langs[0]=="es") {
switch ($ipcountry) {
case "MX": $global_lang = "sp_mx"; break;
case "ES": $global_lang = "sp_sp"; break;
default: $global_lang = "sp_sp"; break;
}
} else if ($langs[0]=="pt") {
switch ($ipcountry) {
case "BR": $global_lang = "pt_br"; break;
case "PT": $global_lang = "pt_pt"; break;
default: $global_lang = "pt_br"; break;
}
} else {
switch ($ipcountry) {
case "MX": $global_lang = "sp_mx"; break;
case "ES": $global_lang = "sp_sp"; break;
case "BR": $global_lang = "pt_br"; break;
case "PT": $global_lang = "pt_pt"; break;
default: $global_lang = "pt_br"; break;
}
}
}
}
}
?>