[ghelda-devel] [60] Transfer part of the HTTP Header parse to inc/ |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/ghelda-devel Archives
]
Revision: 60
Author: odyx
Date: 2009-07-21 20:58:41 +0200 (Tue, 21 Jul 2009)
Log Message:
-----------
Transfer part of the HTTP Header parse to inc/
Modified Paths:
--------------
trunk/inc/g_gettext.php
trunk/init/gettext.php
Modified: trunk/inc/g_gettext.php
===================================================================
--- trunk/inc/g_gettext.php 2009-07-21 18:58:39 UTC (rev 59)
+++ trunk/inc/g_gettext.php 2009-07-21 18:58:41 UTC (rev 60)
@@ -72,9 +72,34 @@
return array($g_GT_oldLocale,$g_GT_oldDomain);
}
-function g_getCorrectLocaleFromHTTPValues($charsets,$languages) {
+function g_getCorrectLocaleFromHTTPValues() {
global $g_GT_supportedLocales;
+ $langChar = LOCALE_DEFAULT;
+ // Get the language given by the "Accept-Language" HTTP header
+ if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) || !isset($_SERVER['HTTP_ACCEPT_CHARSET']))
+ return $langChar;
+ // Create the list of charsets
+ foreach(explode(',',$_SERVER['HTTP_ACCEPT_CHARSET']) as $ccharset) {
+ preg_match("#^(.*?)?(\;q\=(.*))?$#i", $ccharset, $ayM);
+ $q = isset($ayM[3]) ? $ayM[3] : '1.0';
+ $charset = strtolower(trim($ayM[1]));
+ // Special case for '*' => make it a little lower
+ $q = $charset == '*' ? $q-1e-9 : $q;
+ $charsets[$charset] = $q;
+ }
+ arsort($charsets,SORT_NUMERIC);
+
+ // Create the list of languages
+ $selected_q = 0.0;
+ foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $llang) {
+ preg_match("#^(.*?)?(\;q\=(.*))?$#i", $llang, $ayM);
+ $q = isset($ayM[3]) ? $ayM[3] : '1.0';
+ $lang = strtolower(trim($ayM[1]));
+ $languages[$lang] = $q;
+ }
+ arsort($languages,SORT_NUMERIC);
+
// Priority :
// 1) Language (Human)
// 2) Charset (Machine)
Modified: trunk/init/gettext.php
===================================================================
--- trunk/init/gettext.php 2009-07-21 18:58:39 UTC (rev 59)
+++ trunk/init/gettext.php 2009-07-21 18:58:41 UTC (rev 60)
@@ -67,42 +67,16 @@
// Define the locale
if(isset($g_GT_urlLocale)) {
$locale = $g_GT_urlLocale;
- gol('Language choice (URL):',$g_GT_urlLocale);
+ gol('Language choice (URL):',$locale);
} elseif (!empty($g_GT_userLocale)) {
$locale = $g_GT_userLocale;
- gol('Language choice (User setting):',$g_GT_userLocale);
+ gol('Language choice (User setting):',$locale);
} elseif (isset($g_GT_cookieLocale)) {
$locale = $g_GT_cookieLocale;
- gol('Language choice (Cookie):',$g_GT_cookieLocale);
+ gol('Language choice (Cookie):',$locale);
} else {
- $locale = LOCALE_DEFAULT;
- // Get the language given by the "Accept-Language" HTTP header
- if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
- // Create the list of charsets
- foreach(explode(',',$_SERVER['HTTP_ACCEPT_CHARSET']) as $ccharset) {
- preg_match("#^(.*?)?(\;q\=(.*))?$#i", $ccharset, $ayM);
- $q = isset($ayM[3]) ? $ayM[3] : '1.0';
- $charset = strtolower(trim($ayM[1]));
- // Special case for '*' => make it a little lower
- $q = $charset == '*' ? $q-1e-9 : $q;
- $charsets[$charset] = $q;
- }
- arsort($charsets,SORT_NUMERIC);
-
- // Create the list of languages
- $selected_q = 0.0;
- foreach(explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']) as $llang) {
- preg_match("#^(.*?)?(\;q\=(.*))?$#i", $llang, $ayM);
- $q = isset($ayM[3]) ? $ayM[3] : '1.0';
- $lang = strtolower(trim($ayM[1]));
- $languages[$lang] = $q;
- }
- arsort($languages,SORT_NUMERIC);
-
- // Assume that both arrays are already sorted in descending order of q
- $g_GT_HTTP_Locale = g_getCorrectLocaleFromHTTPValues($charsets,$languages);
- }
- gol('Language choice (HTTP Header):',$g_GT_HTTP_Locale);
+ $locale = g_getCorrectLocaleFromHTTPValues($charsets,$languages);
+ gol('Language choice (HTTP Header):',$locale);
}
// header += "Accept-Language: " + m_request.languages + ";q=0.1\r\n";