diff options
author | Friendika <info@friendika.com> | 2011-05-23 17:18:36 -0700 |
---|---|---|
committer | Friendika <info@friendika.com> | 2011-05-23 17:18:36 -0700 |
commit | 3e6180183bdc01edfa01dc4b966daa4081c29604 (patch) | |
tree | 57cc791da7766c07f6c3dcb323ba8539cef9cd23 | |
parent | 3ea145fae7defaf959b04797afc8482bd0190352 (diff) | |
download | volse-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.php | 7 | ||||
-rw-r--r-- | include/auth.php | 4 | ||||
-rw-r--r-- | include/pgettext.php | 51 | ||||
-rw-r--r-- | index.php | 16 | ||||
-rw-r--r-- | mod/openid.php | 6 |
5 files changed, 65 insertions, 19 deletions
@@ -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')) { @@ -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']); |