diff options
author | ArthurHoaro <arthur@hoa.ro> | 2015-03-12 21:43:21 +0100 |
---|---|---|
committer | nodiscc <nodiscc@gmail.com> | 2015-03-31 13:22:20 +0200 |
commit | 880cbf92ca0ee87a4b10a0621e44aa70d019aff7 (patch) | |
tree | a717d4d8cfbabe21db0fb539675f25d74429c53e | |
parent | bec18701801cc140d760c261dd115fda1507a0dd (diff) | |
download | Shaarli-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.php | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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.) |
303 | function autoLocale() | 303 | function 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) | |||
549 | function linkdate2timestamp($linkdate) | 554 | function 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 | ||