aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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