aboutsummaryrefslogtreecommitdiff
path: root/mod/languages/start.php
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2013-11-09 16:17:30 +0100
committerSem <sembrestels@riseup.net>2013-11-09 16:17:30 +0100
commit6834f913fe7ce7d4274a9757661589e9a222b71c (patch)
treec2eb6345bfad6ebabbe31cb1de319037119be404 /mod/languages/start.php
parente58937426578eac71d1447c38ae3f93cbc331bf1 (diff)
parent0f226cf5c4a8d02dbd0bb64cff36a6bb92d72d68 (diff)
downloadelgg-6834f913fe7ce7d4274a9757661589e9a222b71c.tar.gz
elgg-6834f913fe7ce7d4274a9757661589e9a222b71c.tar.bz2
Add 'mod/languages/' from commit '0f226cf5c4a8d02dbd0bb64cff36a6bb92d72d68'
git-subtree-dir: mod/languages git-subtree-mainline: e58937426578eac71d1447c38ae3f93cbc331bf1 git-subtree-split: 0f226cf5c4a8d02dbd0bb64cff36a6bb92d72d68
Diffstat (limited to 'mod/languages/start.php')
-rw-r--r--mod/languages/start.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/mod/languages/start.php b/mod/languages/start.php
new file mode 100644
index 000000000..1b392dd49
--- /dev/null
+++ b/mod/languages/start.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Languages plugin
+ *
+ */
+
+elgg_register_event_handler('init', 'system', 'languages_init');
+
+function languages_init() {
+
+ register_translations(elgg_get_plugins_path() . "languages/languages/es");
+ register_translations(elgg_get_plugins_path() . "languages/languages/nl");
+ register_translations(elgg_get_plugins_path() . "languages/languages/de");
+ register_translations(elgg_get_plugins_path() . "languages/languages/pt");
+ register_translations(elgg_get_plugins_path() . "languages/languages/fr");
+ register_translations(elgg_get_plugins_path() . "languages/languages/ca");
+ register_translations(elgg_get_plugins_path() . "languages/languages/da");
+ register_translations(elgg_get_plugins_path() . "languages/languages/eu");
+ register_translations(elgg_get_plugins_path() . "languages/languages/gl");
+ register_translations(elgg_get_plugins_path() . "languages/languages/it");
+ register_translations(elgg_get_plugins_path() . "languages/languages/ja");
+ register_translations(elgg_get_plugins_path() . "languages/languages/sr");
+ register_translations(elgg_get_plugins_path() . "languages/languages/th");
+ register_translations(elgg_get_plugins_path() . "languages/languages/zh");
+
+ if (!elgg_is_logged_in()) {
+ global $CONFIG;
+ if ($useragent_language = languages_get_useragent_language()) {
+ $CONFIG->language = $useragent_language;
+ }
+ }
+
+}
+
+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;
+ }
+}
+