aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-05-23 17:18:36 -0700
committerFriendika <info@friendika.com>2011-05-23 17:18:36 -0700
commit3e6180183bdc01edfa01dc4b966daa4081c29604 (patch)
tree57cc791da7766c07f6c3dcb323ba8539cef9cd23
parent3ea145fae7defaf959b04797afc8482bd0190352 (diff)
downloadvolse-hubzilla-3e6180183bdc01edfa01dc4b966daa4081c29604.tar.gz
volse-hubzilla-3e6180183bdc01edfa01dc4b966daa4081c29604.tar.bz2
volse-hubzilla-3e6180183bdc01edfa01dc4b966daa4081c29604.zip
improved browser language detect, set user language on login
-rw-r--r--boot.php7
-rw-r--r--include/auth.php4
-rw-r--r--include/pgettext.php51
-rw-r--r--index.php16
-rw-r--r--mod/openid.php6
5 files changed, 65 insertions, 19 deletions
diff --git a/boot.php b/boot.php
index 1a6bf622c..48d0d79ad 100644
--- 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
+}}
+
diff --git a/include/auth.php b/include/auth.php
index 1c430406e..382d2c658 100644
--- a/include/auth.php
+++ b/include/auth.php
@@ -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'])
);
diff --git a/include/pgettext.php b/include/pgettext.php
index 2ffee70bc..37e09b54d 100644
--- a/include/pgettext.php
+++ b/include/pgettext.php
@@ -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')) {
diff --git a/index.php b/index.php
index 05eef6c6e..eb75585c4 100644
--- 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);
diff --git a/mod/openid.php b/mod/openid.php
index c3c6c11e9..7bf8c299c 100644
--- a/mod/openid.php
+++ b/mod/openid.php
@@ -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']);