From: Reini U. <ru...@us...> - 2004-12-26 17:15:46
|
Update of /cvsroot/phpwiki/phpwiki/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1233 Modified Files: config.php Log Message: new reverse locale detection on DEFAULT_LANGUAGE="", ja default euc-jp again Index: config.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/config.php,v retrieving revision 1.126 retrieving revision 1.127 diff -u -2 -b -p -d -r1.126 -r1.127 --- config.php 20 Dec 2004 16:05:00 -0000 1.126 +++ config.php 26 Dec 2004 17:15:32 -0000 1.127 @@ -107,7 +107,12 @@ function isBrowserKonqueror($version = f return browserDetect('Konqueror/'); } +// FIXME: MacOSX Safarai has certain limitations. Need detection and patches. +function isBrowserSafari($version = false) { + if ($version) return browserDetect('Safari/') and browserVersion() >= $version; + return browserDetect('Safari/'); +} /** - * Smart? setlocale(). + * Smart setlocale(). * * This is a version of the builtin setlocale() which is @@ -122,6 +127,4 @@ function isBrowserKonqueror($version = f */ function guessing_setlocale ($category, $locale) { - if ($res = setlocale($category, $locale)) - return $res; $alt = array('en' => array('C', 'en_US', 'en_GB', 'en_AU', 'en_CA', 'english'), 'de' => array('de_DE', 'de_DE', 'de_DE@euro', @@ -133,7 +136,23 @@ function guessing_setlocale ($category, 'it' => array('it_IT'), 'sv' => array('sv_SE'), - 'ja' => array('ja_JP','ja_JP.eucJP','japanese.euc'), + 'ja.utf-8' => array('ja_JP','ja_JP.utf-8','japanese'), + 'ja.euc-jp' => array('ja_JP','ja_JP.eucJP','japanese.euc'), 'zh' => array('zh_TW', 'zh_CN'), ); + if (!$locale) { + // do the reverse: return the detected locale collapsed to our LANG + $locale = setlocale($category,''); + if ($locale) { + if (strstr($locale, '_')) list ($lang) = split('_', $locale); + else $lang = $locale; + if (strlen($lang) > 2) { + foreach ($alt as $try => $locs) { + if (in_array($locale, $locs) or in_array($lang, $locs)) { + return $try; + } + } + } + } + } if (strlen($locale) == 2) $lang = $locale; @@ -166,5 +185,5 @@ function guessing_setlocale ($category, // [99ms] function update_locale($loc) { - //require_once(dirname(__FILE__)."/FileFinder.php"); + if (!$loc) { $newlocale = guessing_setlocale(LC_ALL, $loc); // [56ms] if (!$newlocale) { @@ -172,4 +191,5 @@ function update_locale($loc) { // => LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C //$loc = setlocale(LC_CTYPE, ''); // pull locale from environment. + //require_once(dirname(__FILE__)."/FileFinder.php"); $newlocale = FileFinder::_get_lang(); list ($newlocale,) = split('_', $newlocale, 2); @@ -178,4 +198,6 @@ function update_locale($loc) { //return false; } + $loc = $newlocale; + } //if (substr($newlocale,0,2) == $loc) // don't update with C or failing setlocale if (!isset($GLOBALS['LANG'])) $GLOBALS['LANG'] = $loc; @@ -183,10 +205,4 @@ function update_locale($loc) { // programs we run will get the right locale.) // - // If PHP is in safe mode, this is not allowed, - // so hide errors... - @putenv("LC_ALL=$newlocale"); - @putenv("LANG=$newlocale"); - @putenv("LANGUAGE=$newlocale"); - if (!function_exists ('bindtextdomain')) { // Reinitialize translation array. @@ -198,4 +214,10 @@ function update_locale($loc) { include($lcfile); } + } else { + // If PHP is in safe mode, this is not allowed, + // so hide errors... + @putenv("LC_ALL=$loc"); + @putenv("LANG=$loc"); + @putenv("LANGUAGE=$loc"); } @@ -221,8 +243,8 @@ function update_locale($loc) { $x = setlocale(LC_CTYPE, 'en_US.' . $GLOBALS['charset']); } else { - $x = setlocale(LC_CTYPE, $newlocale); + $x = setlocale(LC_CTYPE, $loc); } - return $newlocale; + return $loc; } @@ -257,9 +279,14 @@ function pcre_fix_posix_classes ($regexp if (!isset($charset)) $charset = CHARSET; // get rid of constant. pref is dynamic and language specific - if (in_array($GLOBALS['LANG'],array('zh'))) + if (in_array($GLOBALS['LANG'], array('zh'))) $charset = 'utf-8'; - if (in_array($GLOBALS['LANG'],array('ja'))) + if (strstr($GLOBALS['LANG'],'.utf-8')) $charset = 'utf-8'; - //$charset = 'euc-jp'; + elseif (strstr($GLOBALS['LANG'],'.euc-jp')) + $charset = 'euc-jp'; + elseif (in_array($GLOBALS['LANG'], array('ja'))) + //$charset = 'utf-8'; + $charset = 'euc-jp'; + if (strtolower($charset) == 'utf-8') { // thanks to John McPherson // until posix class names/pcre work with utf-8 @@ -412,4 +439,7 @@ function getUploadDataPath() { // $Log$ +// Revision 1.127 2004/12/26 17:15:32 rurban +// new reverse locale detection on DEFAULT_LANGUAGE="", ja default euc-jp again +// // Revision 1.126 2004/12/20 16:05:00 rurban // gettext msg unification |