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
|
<?php
/**
* Languages plugin
*
*/
function languages_get_useragent_language() {
global $CONFIG;
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
register_translations($CONFIG->path . "languages/", true);
$available_languages = array_keys($CONFIG->translations);
$accepted_languages = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
foreach ($accepted_languages as $i => $accepted_language) {
$accepted_languages[$i] = trim(array_shift(preg_split("/[-;]/", $accepted_language)));
}
$langs = array_intersect($accepted_languages, $available_languages);
if (count($langs) > 0) {
return array_shift($langs);
}
return false;
}
}
register_translations(elgg_get_plugins_path() . "languages/languages/es", true);
register_translations(elgg_get_plugins_path() . "languages/languages/nl", true);
register_translations(elgg_get_plugins_path() . "languages/languages/de", true);
register_translations(elgg_get_plugins_path() . "languages/languages/pt", true);
register_translations(elgg_get_plugins_path() . "languages/languages/fr", true);
register_translations(elgg_get_plugins_path() . "languages/languages/ca", true);
register_translations(elgg_get_plugins_path() . "languages/languages/da", true);
register_translations(elgg_get_plugins_path() . "languages/languages/eu", true);
register_translations(elgg_get_plugins_path() . "languages/languages/gl", true);
register_translations(elgg_get_plugins_path() . "languages/languages/it", true);
register_translations(elgg_get_plugins_path() . "languages/languages/ja", true);
register_translations(elgg_get_plugins_path() . "languages/languages/sr", true);
register_translations(elgg_get_plugins_path() . "languages/languages/th", true);
register_translations(elgg_get_plugins_path() . "languages/languages/zh", true);
if (!elgg_is_logged_in()) {
global $CONFIG;
if ($useragent_language = languages_get_useragent_language()) {
$CONFIG->language = $useragent_language;
}
}
|