-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlangfunctions.php
More file actions
51 lines (42 loc) · 1.25 KB
/
Copy pathlangfunctions.php
File metadata and controls
51 lines (42 loc) · 1.25 KB
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
<?PHP
function getLanguages() {
$languages = array(
'en' => 'English',
'zh_CN' => '中文',
);
return $languages;
}
function getAnglicizedLanguages() {
$languages = array(
'en' => 'English',
'zh_CN' => 'Chinese',
);
return $languages;
}
function validLang($langCode) {
$languages = getLanguages();
return array_key_exists($langCode, $languages);
}
// Picks the best language to display the website in by picking the first language in the Accept-Language header that is supported
// Defaults to English if no other languages are found
function getAcceptLanguage() {
$languages = getLanguages();
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
return 'en';
$langarray = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($langarray as $value) {
$langCode = array_shift(explode(';', $value));
$langCode = substr($langCode, 0, 2);
if ($langCode == 'zh')
$langCode = 'zh_CN';
if (array_key_exists($langCode, $languages))
return $langCode;
else
return 'en';
}
}
// turns the text into a translation-array compatible key by replacing spaces with underscores and CAPITALIZING
function keyify($text) {
return strtoupper(str_replace(' ', '_', $text));
}
?>