diff options
author | ArthurHoaro <arthur@hoa.ro> | 2015-03-12 21:43:21 +0100 |
---|---|---|
committer | nodiscc <nodiscc@gmail.com> | 2015-04-05 22:01:43 +0200 |
commit | 8438a2e5d0cb90a869d67516c6e6cf756f77a588 (patch) | |
tree | 05504c9c9cba5ab9f283debd1dfb4f2daab6d466 | |
parent | 82cfe1fe9649880e9653c61bdc51455af32e7bcd (diff) | |
download | Shaarli-8438a2e5d0cb90a869d67516c6e6cf756f77a588.tar.gz Shaarli-8438a2e5d0cb90a869d67516c6e6cf756f77a588.tar.zst Shaarli-8438a2e5d0cb90a869d67516c6e6cf756f77a588.zip |
Fixes autoLocale function by trying several way to find a correct one.
Fix https://github.com/shaarli/Shaarli/issues/184
-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 | ||