From f9a2fa3840a9d68729ce940bb21950dd4712d147 Mon Sep 17 00:00:00 2001 From: Lars Kneschke Date: Sat, 6 Jan 2001 21:09:05 +0000 Subject: [PATCH] added funtions for detecting users preferred language automatically --- phpgwapi/inc/phpgw.inc.php | 1 + phpgwapi/inc/phpgw_accounts_shared.inc.php | 2 + phpgwapi/inc/phpgw_common.inc.php | 49 ++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/phpgwapi/inc/phpgw.inc.php b/phpgwapi/inc/phpgw.inc.php index 1a6b7e197a..35833dfb53 100644 --- a/phpgwapi/inc/phpgw.inc.php +++ b/phpgwapi/inc/phpgw.inc.php @@ -195,6 +195,7 @@ $this->preferences->account_id = $phpgw_info["user"]["account_id"]; } + $this->translation = new translation; $this->acl = new acl; diff --git a/phpgwapi/inc/phpgw_accounts_shared.inc.php b/phpgwapi/inc/phpgw_accounts_shared.inc.php index c283fd6b1f..cb7ed6c76b 100644 --- a/phpgwapi/inc/phpgw_accounts_shared.inc.php +++ b/phpgwapi/inc/phpgw_accounts_shared.inc.php @@ -225,6 +225,8 @@ $db2->next_record(); $pref_info = $db2->f("preference_value"); $this->preference = unserialize($pref_info); + if ($this->preference["common"]["lang"] == "auto") + $this->preference["common"]["lang"] = $phpgw->common->getPreferredLanguage(); } } diff --git a/phpgwapi/inc/phpgw_common.inc.php b/phpgwapi/inc/phpgw_common.inc.php index 0047526f35..bb93774c91 100644 --- a/phpgwapi/inc/phpgw_common.inc.php +++ b/phpgwapi/inc/phpgw_common.inc.php @@ -62,6 +62,55 @@ var $key = ""; var $crypto; + // return a array of installed languages + function getInstalledLanguages() + { + global $phpgw; + + $phpgw->db->query("select distinct lang from lang"); + while (@$phpgw->db->next_record()) + { + $installedLanguages[$phpgw->db->f("lang")] = $phpgw->db->f("lang"); + } + + return $installedLanguages; + } + + // return the preferred language of the users + // it's using HTTP_ACCEPT_LANGUAGE (send from the users browser) + // and ...(to find out which languages are installed) + function getPreferredLanguage() + { + global $HTTP_ACCEPT_LANGUAGE; + + // create a array of languages the user is accepting + $userLanguages = explode(",",$HTTP_ACCEPT_LANGUAGE); + $supportedLanguages = $this->getInstalledLanguages(); + + // find usersupported language + while (list($key,$value) = each($userLanguages)) + { + // remove everything behind "-" example: de-de + $value = trim($value); + $pieces = explode("-", $value); + $value = $pieces[0]; + # print "current lang $value
"; + if ($supportedLanguages[$value]) + { + $retValue=$value; + break; + } + } + + // no usersupported language found -> return english + if (empty($retValue)) + { + $retValue="en"; + } + + return $retValue; + } + // connect to the ldap server and return a handle function ldapConnect($host = "", $dn = "", $passwd = "") {