diff options
author | Sem <sembrestels@riseup.net> | 2012-10-30 04:45:52 +0100 |
---|---|---|
committer | Sem <sembrestels@riseup.net> | 2012-10-30 04:45:52 +0100 |
commit | 22bf840f4b74c040296566871e253d0bb29eaf75 (patch) | |
tree | 9fa90efb99f53aedefee741d8f035fc03d74a8c4 /start.php | |
parent | dc25beb9cef75b97d09651bf93ea0a390795f02e (diff) | |
download | elgg-22bf840f4b74c040296566871e253d0bb29eaf75.tar.gz elgg-22bf840f4b74c040296566871e253d0bb29eaf75.tar.bz2 |
Added useragent language support.
Diffstat (limited to 'start.php')
-rw-r--r-- | start.php | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -4,6 +4,27 @@ * */ +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); @@ -18,3 +39,10 @@ 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; + } +}
\ No newline at end of file |