]> git.mxchange.org Git - friendica.git/commitdiff
improved browser language detect, set user language on login
authorFriendika <info@friendika.com>
Tue, 24 May 2011 00:18:36 +0000 (17:18 -0700)
committerFriendika <info@friendika.com>
Tue, 24 May 2011 00:18:36 +0000 (17:18 -0700)
boot.php
include/auth.php
include/pgettext.php
index.php
mod/openid.php

index 1a6bf622c4f23d3cad3e4165a5186cf9c17b0a0d..48d0d79ad61f99914ec441fed59f25b8662c9f1c 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -4,7 +4,7 @@ set_time_limit(0);
 ini_set('pcre.backtrack_limit', 250000);
 
 
-define ( 'FRIENDIKA_VERSION',      '2.2.988' );
+define ( 'FRIENDIKA_VERSION',      '2.2.989' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.21'    );
 define ( 'DB_UPDATE_VERSION',      1054      );
 
@@ -2707,6 +2707,8 @@ function unamp($s) {
 }}
 
 
+
+
 if(! function_exists('lang_selector')) {
 function lang_selector() {
        global $lang;
@@ -2748,4 +2750,5 @@ function is_site_admin() {
        if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
                return true;
        return false;
-}}
\ No newline at end of file
+}}
+
index 1c430406e9e84328f8d69bac078d0302aa3dafde..382d2c65877da5e1f82710a9e16cf4192217c4d5 100644 (file)
@@ -232,9 +232,11 @@ else {
                        $_SESSION['cid'] = $a->cid;
                }
 
+               $l = get_language();
 
-               q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
+               q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1",
                        dbesc(datetime_convert()),
+                       dbesc($l),
                        intval($_SESSION['uid'])
                );
 
index 2ffee70bcc64c8fcae9909643e1bfc7cab2f46d1..37e09b54dacf2d7b5c9c35e247f65644862f8c99 100644 (file)
@@ -1,8 +1,59 @@
 <?php
+
 /**
  * translation support
  */
 
+
+/**
+ *
+ * Get the language setting directly from system variables, bypassing get_config()
+ * as database may not yet be configured.
+ * 
+ * If possible, we use the value from the browser.
+ *
+ */
+
+
+if(! function_exists('get_language')) {
+function get_language() {
+
+       if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
+           // break up string into pieces (languages and q factors)
+       preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', 
+                       $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
+
+       if (count($lang_parse[1])) {
+               // create a list like "en" => 0.8
+               $langs = array_combine($lang_parse[1], $lang_parse[4]);
+       
+               // set default to 1 for any without q factor
+               foreach ($langs as $lang => $val) {
+               if ($val === '') $langs[$lang] = 1;
+               }
+
+               // sort list based on value     
+               arsort($langs, SORT_NUMERIC);
+       }
+       }
+
+       if(isset($langs) && count($langs)) {
+               foreach ($langs as $lang => $v) {
+                       if(file_exists("view/$lang") && is_dir("view/$lang")) {
+                               $preferred = $lang;
+                               break;
+                       }
+               }
+       }
+
+       if(isset($preferred))
+               return $preferred;
+
+       return ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
+}}
+
+
+
 // load string translation table for alternate language
 
 if(! function_exists('load_translation_table')) {
index 05eef6c6e0bfe0f2e7475b29798ff96866702e6d..eb75585c48d909b63838cff51cf113eae44445b8 100644 (file)
--- a/index.php
+++ b/index.php
@@ -29,22 +29,8 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false
 
 @include(".htconfig.php");
 
-/**
- *
- * Get the language setting directly from system variables, bypassing get_config()
- * as database may not yet be configured.
- * 
- * If possible, we use the value from the browser.
- *
- */
-
-if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
-       $langs = preg_split("/[,-]/",$_SERVER['HTTP_ACCEPT_LANGUAGE'],2);
-       $lang = $langs[0];
-} else {
-       $lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
-}
 
+$lang = get_language();
        
 load_translation_table($lang);
 
index c3c6c11e9e8f9a02a34ca84b240d5e4bb5a05ba1..7bf8c299c8c76a5aaff49f7ea27976ad87ad6451 100644 (file)
@@ -103,11 +103,15 @@ function openid_content(&$a) {
                                $_SESSION['cid'] = $a->cid;
                        }
 
-                       q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
+                       $l = get_language();
+
+                       q("UPDATE `user` SET `login_date` = '%s', `language` = '%s' WHERE `uid` = %d LIMIT 1",
                                dbesc(datetime_convert()),
+                               dbesc($l),
                                intval($_SESSION['uid'])
                        );
 
+
                        header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
                        if(($a->module !== 'home') && isset($_SESSION['return_url']))
                                goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);