aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2015-03-12 21:43:21 +0100
committernodiscc <nodiscc@gmail.com>2015-03-31 13:22:20 +0200
commit880cbf92ca0ee87a4b10a0621e44aa70d019aff7 (patch)
treea717d4d8cfbabe21db0fb539675f25d74429c53e
parentbec18701801cc140d760c261dd115fda1507a0dd (diff)
downloadShaarli-880cbf92ca0ee87a4b10a0621e44aa70d019aff7.tar.gz
Shaarli-880cbf92ca0ee87a4b10a0621e44aa70d019aff7.tar.zst
Shaarli-880cbf92ca0ee87a4b10a0621e44aa70d019aff7.zip
Fixes autoLocale function by trying several way to find a correct one.
-rw-r--r--index.php13
1 files changed, 9 insertions, 4 deletions
diff --git a/index.php b/index.php
index 9ab70f6c..7795a597 100644
--- a/index.php
+++ b/index.php
@@ -302,12 +302,17 @@ function keepMultipleSpaces($text)
302// (Note that is may not work on your server if the corresponding local is not installed.) 302// (Note that is may not work on your server if the corresponding local is not installed.)
303function autoLocale() 303function autoLocale()
304{ 304{
305 $loc='en_US'; // Default if browser does not send HTTP_ACCEPT_LANGUAGE 305 $attempts = array('en_US'); // Default if browser does not send HTTP_ACCEPT_LANGUAGE
306 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3" 306 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3"
307 { // (It's a bit crude, but it works very well. Preferred language is always presented first.) 307 { // (It's a bit crude, but it works very well. Preferred language is always presented first.)
308 if (preg_match('/([a-z]{2}(-[a-z]{2})?)/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) $loc=$matches[1]; 308 if (preg_match('/([a-z]{2})-?([a-z]{2})?/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) {
309 $loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
310 $attempts = array($loc, str_replace('_', '-', $loc),
311 $loc . '_' . strtoupper($loc), $loc . '_' . $loc,
312 $loc . '-' . strtoupper($loc), $loc . '-' . $loc);
313 }
309 } 314 }
310 setlocale(LC_TIME,$loc); // LC_TIME = Set local for date/time format only. 315 setlocale(LC_TIME, $attempts); // LC_TIME = Set local for date/time format only.
311} 316}
312 317
313// ------------------------------------------------------------------------------------------ 318// ------------------------------------------------------------------------------------------
@@ -549,7 +554,7 @@ function endsWith($haystack,$needle,$case=true)
549function linkdate2timestamp($linkdate) 554function linkdate2timestamp($linkdate)
550{ 555{
551 $Y=$M=$D=$h=$m=$s=0; 556 $Y=$M=$D=$h=$m=$s=0;
552 $r = sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s); 557 sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s);
553 return mktime($h,$m,$s,$M,$D,$Y); 558 return mktime($h,$m,$s,$M,$D,$Y);
554} 559}
555 560