aboutsummaryrefslogtreecommitdiff
path: root/start.php
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2012-10-30 04:45:52 +0100
committerSem <sembrestels@riseup.net>2012-10-30 04:45:52 +0100
commit22bf840f4b74c040296566871e253d0bb29eaf75 (patch)
tree9fa90efb99f53aedefee741d8f035fc03d74a8c4 /start.php
parentdc25beb9cef75b97d09651bf93ea0a390795f02e (diff)
downloadelgg-22bf840f4b74c040296566871e253d0bb29eaf75.tar.gz
elgg-22bf840f4b74c040296566871e253d0bb29eaf75.tar.bz2
Added useragent language support.
Diffstat (limited to 'start.php')
-rw-r--r--start.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/start.php b/start.php
index 2b9c4e543..a481c8877 100644
--- a/start.php
+++ b/start.php
@@ -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