Fixes autoLocale function by trying several way to find a correct one.
Fix https://github.com/shaarli/Shaarli/issues/184
This commit is contained in:
parent
1f3a7f78a0
commit
31fc9518a3
1 changed files with 11 additions and 6 deletions
17
index.php
17
index.php
|
@ -289,12 +289,17 @@ function keepMultipleSpaces($text)
|
||||||
// (Note that is may not work on your server if the corresponding local is not installed.)
|
// (Note that is may not work on your server if the corresponding local is not installed.)
|
||||||
function autoLocale()
|
function autoLocale()
|
||||||
{
|
{
|
||||||
$loc='en_US'; // Default if browser does not send HTTP_ACCEPT_LANGUAGE
|
$attempts = array('en_US'); // Default if browser does not send HTTP_ACCEPT_LANGUAGE
|
||||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // eg. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3"
|
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) // e.g. "fr,fr-fr;q=0.8,en;q=0.5,en-us;q=0.3"
|
||||||
{ // (It's a bit crude, but it works very well. Prefered language is always presented first.)
|
{ // (It's a bit crude, but it works very well. Preferred language is always presented first.)
|
||||||
if (preg_match('/([a-z]{2}(-[a-z]{2})?)/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) $loc=$matches[1];
|
if (preg_match('/([a-z]{2})-?([a-z]{2})?/i',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches)) {
|
||||||
|
$loc = $matches[1] . (!empty($matches[2]) ? '_' . strtoupper($matches[2]) : '');
|
||||||
|
$attempts = array($loc, str_replace('_', '-', $loc),
|
||||||
|
$loc . '_' . strtoupper($loc), $loc . '_' . $loc,
|
||||||
|
$loc . '-' . strtoupper($loc), $loc . '-' . $loc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setlocale(LC_TIME,$loc); // LC_TIME = Set local for date/time format only.
|
setlocale(LC_TIME, $attempts); // LC_TIME = Set local for date/time format only.
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------
|
||||||
|
@ -556,7 +561,7 @@ function endsWith($haystack,$needle,$case=true)
|
||||||
function linkdate2timestamp($linkdate)
|
function linkdate2timestamp($linkdate)
|
||||||
{
|
{
|
||||||
$Y=$M=$D=$h=$m=$s=0;
|
$Y=$M=$D=$h=$m=$s=0;
|
||||||
$r = sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s);
|
sscanf($linkdate,'%4d%2d%2d_%2d%2d%2d',$Y,$M,$D,$h,$m,$s);
|
||||||
return mktime($h,$m,$s,$M,$D,$Y);
|
return mktime($h,$m,$s,$M,$D,$Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue