summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsoranzo2004-06-18 14:47:21 +0000
committersoranzo2004-06-18 14:47:21 +0000
commit078be3551bc0f576bf43191bd3bcce54b21fb8a6 (patch)
tree171e6b8f9a97ff44ecb0aa1a6bb08834b2347428
parentfa275425820cc96095195e3a1bc7469028696966 (diff)
Patch for language preferencies from browser by Markus Bertheau, edited by me. Please test
-rw-r--r--HISTORY1
-rw-r--r--libraries/errorhandler.inc.php4
-rw-r--r--libraries/lib.inc.php27
-rwxr-xr-xlogin.php82
4 files changed, 81 insertions, 33 deletions
diff --git a/HISTORY b/HISTORY
index d02ca8cc..4a875f63 100644
--- a/HISTORY
+++ b/HISTORY
@@ -6,6 +6,7 @@ Version 3.5-dev
Features
* Context-sensitive online help system
+* Use language preferencies from browser (Markus Bertheau, Nicola Soranzo)
Translations
* Arabic from Zaki
diff --git a/libraries/errorhandler.inc.php b/libraries/errorhandler.inc.php
index f8a93feb..0a8b1054 100644
--- a/libraries/errorhandler.inc.php
+++ b/libraries/errorhandler.inc.php
@@ -3,7 +3,7 @@
/**
* Overrides default ADODB error handler to provide nicer error handling.
*
- * $Id: errorhandler.inc.php,v 1.14 2003/12/17 09:11:32 chriskl Exp $
+ * $Id: errorhandler.inc.php,v 1.15 2004/06/18 14:47:21 soranzo Exp $
*/
define('ADODB_ERROR_HANDLER','Error_Handler');
@@ -20,7 +20,7 @@ define('ADODB_ERROR_HANDLER','Error_Handler');
*/
function Error_Handler($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
{
- global $lang;
+ global $lang, $conf;
global $misc, $appName, $appVersion, $appLangFiles;
switch($fn) {
diff --git a/libraries/lib.inc.php b/libraries/lib.inc.php
index 0767a22f..96dedf8b 100644
--- a/libraries/lib.inc.php
+++ b/libraries/lib.inc.php
@@ -3,7 +3,7 @@
/**
* Function library read in upon startup
*
- * $Id: lib.inc.php,v 1.80 2004/06/13 07:08:29 chriskl Exp $
+ * $Id: lib.inc.php,v 1.81 2004/06/18 14:47:21 soranzo Exp $
*/
// Set error reporting level to max
@@ -25,7 +25,7 @@
include('./conf/config.inc.php');
}
else {
- echo "Configuration error: Copy conf/config.inc.php-dist to conf/config.inc.php and edit appropriately.";
+ echo 'Configuration error: Copy conf/config.inc.php-dist to conf/config.inc.php and edit appropriately.';
exit;
}
@@ -57,24 +57,13 @@
'turkish' => 'Türkçe'
);
- // Language settings. Always include english.php, since it's the master
- // language file, and then overwrite it with the user-specified language if
- // one has not been selected yet.
+ // Always include english.php, since it's the master language file
if (!isset($conf['default_lang'])) $conf['default_lang'] = 'english';
$lang = array();
- include_once('./lang/recoded/english.php');
- // Include default language over the top - we really should try to avoid this
- // in the case when the user has chosen a language.
- include_once("./lang/recoded/" . strtolower($conf['default_lang']) . ".php");
-
- // Check for config file version mismatch
- if (!isset($conf['version']) || $conf['base_version'] > $conf['version']) {
- echo $lang['strbadconfig'];
- exit;
- }
+ require_once('./lang/recoded/english.php');
// Create Misc class references
- include_once('./classes/Misc.php');
+ require_once('./classes/Misc.php');
$misc = new Misc();
// Start session (if not auto-started)
@@ -120,6 +109,9 @@
exit;
}
+ // Import language file
+ include('./lang/recoded/' . strtolower($_SESSION['webdbLanguage']) . '.php');
+
// If extra login check fails, back to the login screen
$_allowed = $misc->checkExtraSecurity();
if (!$_allowed) {
@@ -127,9 +119,6 @@
exit;
}
- // Import language file
- include("./lang/recoded/" . strtolower($_SESSION['webdbLanguage']) . ".php");
-
// Check database support is properly compiled in
if (!function_exists('pg_connect')) {
echo $lang['strnotloaded'];
diff --git a/login.php b/login.php
index 597d5204..e06627b6 100755
--- a/login.php
+++ b/login.php
@@ -3,27 +3,85 @@
/**
* Login screen
*
- * $Id: login.php,v 1.16 2004/05/26 11:27:00 soranzo Exp $
+ * $Id: login.php,v 1.17 2004/06/18 14:47:21 soranzo Exp $
*/
// This needs to be an include once to prevent lib.inc.php infinite recursive includes.
// Check to see if the configuration file exists, if not, explain
- include_once('./libraries/lib.inc.php');
+ require_once('./libraries/lib.inc.php');
- // Unfortunately, since sometimes lib.inc.php has been included, but we still
- // need the config variables
- if (file_exists('conf/config.inc.php')) {
- require('conf/config.inc.php');
+ // Prepare form variables
+ if (!isset($_POST['formServer'])) $_POST['formServer'] = '';
+ if (!isset($_POST['formLanguage'])) {
+ // Parse the user acceptable language in HTTP_ACCEPT_LANGUAGE
+ // ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 )
+ // If there's one available, then overwrite the default language.
+ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
+ $userLanguage = '';
+ $userLanguages = array();
+ $acceptableLanguages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ foreach ($acceptableLanguages as $accLang) {
+ $languageInfos = explode(';', trim($accLang));
+ $languageRange = strtolower($languageInfos[0]);
+ if (isset($languageInfos[1]) && substr($languageInfos[1], 0, 2) == 'q=')
+ $languageQuality = (float)substr($languageInfos[1], 2, 5);
+ else
+ $languageQuality = 1;
+ // If the language is already in the array, check that we
+ // don't overwrite its quality value with a lower one
+ if ((!array_key_exists($languageRange, $userLanguages))
+ || ($userLanguages[$languageRange] < $languageQuality))
+ $userLanguages[$languageRange] = $languageQuality;
+ }
+ arsort($userLanguages, SORT_NUMERIC);
+
+ // if it's available 'language-country', but not general 'language' translation
+ // (eg. 'portuguese-br', but not 'portuguese')
+ // specify both 'la' => 'language-country' and 'la-co' => 'language-country'.
+ // See http://www.w3.org/WAI/ER/IG/ert/iso639.htm for language codes
+ $availableLanguages = array(
+ 'af' => 'afrikaans',
+ 'zh' => 'chinese-tr',
+ 'zh-cn' => 'chinese-sim',
+ 'cs' => 'czech',
+ 'nl' => 'dutch',
+ 'en' => 'english',
+ 'fr' => 'french',
+ 'de' => 'german',
+ 'hu' => 'hungarian',
+ 'it' => 'italian',
+ 'ja' => 'japanese',
+ 'pl' => 'polish',
+ 'pt' => 'portuguese-br',
+ 'pt-br' => 'portuguese-br',
+ 'ru' => 'russian',
+ 'sk' => 'slovak',
+ 'sv' => 'swedish',
+ 'es' => 'spanish',
+ 'sv' => 'swedish',
+ 'tr' => 'turkish'
+ );
+
+ reset($userLanguages);
+ do {
+ $languageRange = key($userLanguages);
+ if (array_key_exists($languageRange, $availableLanguages)) {
+ $userLanguage = $availableLanguages[$languageRange];
+ }
+ } while ($userLanguage == '' && next($userLanguages));
+ if ($userLanguage != '') $conf['default_lang'] = $userLanguage;
+ }
+ $_POST['formLanguage'] = $conf['default_lang'];
+ // Include default language over english.
+ include_once('./lang/recoded/' . strtolower($conf['default_lang']) . '.php');
}
- else {
- echo "Configuration Error: You must rename/copy config.inc.php-dist to config.inc.php and set your appropriate settings";
+
+ // Check for config file version mismatch
+ if (!isset($conf['version']) || $conf['base_version'] > $conf['version']) {
+ echo $lang['strbadconfig'];
exit;
}
- // Prepare form variables
- if (!isset($_POST['formServer'])) $_POST['formServer'] = '';
- if (!isset($_POST['formLanguage'])) $_POST['formLanguage'] = $conf['default_lang'];
-
// Force encoding to UTF-8
$lang['appcharset'] = 'UTF-8';