From 3e6180183bdc01edfa01dc4b966daa4081c29604 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 23 May 2011 17:18:36 -0700 Subject: improved browser language detect, set user language on login --- include/auth.php | 4 +++- include/pgettext.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'include') 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 @@ 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')) { -- cgit v1.2.3