-
Notifications
You must be signed in to change notification settings - Fork 8
/
locale.php
77 lines (71 loc) · 2.48 KB
/
locale.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
<?php
// load locale from GET
if (empty($fixed_locale)) {
if (! array_key_exists('locale', $_REQUEST)) {
if (array_key_exists('userlocale', $_COOKIE)) {
// load locale from cookie
$locale = $_COOKIE['userlocale'];
} else {
// load locale according to HTTP_ACCEPT_LANGUAGE
preg_match('/^([a-z]+)-*([a-z]*)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
$locale = $matches[1];
$locale1 = $locale;
if (! empty($matches[2])) {
$locale2 = strtoupper($matches[2]);
$locale .= '_' . $locale2;
}
}
} else {
$locale = $_REQUEST['locale'];
// save new locale to cookie
echo "<meta http-equiv='Set-Cookie' content='userlocale=$locale;expires=Friday, 31-Dec-2099 23:59:59 GMT;'>";
}
} else {
$locale = $fixed_locale;
}
if (empty($locale1)) {
$locale1 = substr($locale, 0, 2);
}
// set PHP locale
if (file_exists("locale/$locale/LC_MESSAGES/WebAnywhere.php")) {
include("locale/$locale/LC_MESSAGES/WebAnywhere.php");
} else if (file_exists("locale/$locale1/LC_MESSAGES/WebAnywhere.php")) {
include("locale/$locale1/LC_MESSAGES/WebAnywhere.php");
} else {
function wa_gettext($text) {
return $text;
}
}
// set Javascript locale
if (file_exists("locale/$locale/LC_MESSAGES/WebAnywhere.js")) {
echo "<script type='text/javascript' charset='utf-8' src='locale/$locale/LC_MESSAGES/WebAnywhere.js'></script>";
} else if (file_exists("locale/$locale1/LC_MESSAGES/WebAnywhere.js")) {
echo "<script type='text/javascript' charset='utf-8' src='locale/$locale1/LC_MESSAGES/WebAnywhere.js'></script>";
} else {
echo "<script type='text/javascript'>function wa_gettext(text) { return text; }</script>";
}
// set voice
if (empty($sound_url_base)) {
if (array_key_exists('voice', $_REQUEST) &&
array_key_exists($_REQUEST['voice'], $voices)) {
$sound_url_base = $voices[$_REQUEST['voice']];
} else if (array_key_exists($locale, $voices)) {
$sound_url_base = $voices[$locale];
} else {
$sound_url_base = $voices["en"];
}
}
// set home page
if (empty($default_content_url)) {
if (array_key_exists($locale, $home_pages)) {
$default_content_url = $home_pages[$locale];
} else if (array_key_exists($locale1, $home_pages)) {
$default_content_url = $home_pages[$locale1];
} else if (array_key_exists('en', $home_pages)) {
$default_content_url = $home_pages['en'];
} else {
$default_content_url = '';
}
}
echo "<script type='text/javascript'>top.sound_url_base='$sound_url_base';</script>";
?>