mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 15:33:23 +01:00
use Accept-Language header before logging into setup / user selected a language
This commit is contained in:
parent
37957a49f4
commit
96bcda7433
@ -195,9 +195,10 @@ class setup
|
||||
/**
|
||||
* Get configuration language from $_POST or $_SESSION and validate it
|
||||
*
|
||||
* @param boolean $use_accept_language =false true: use Accept-Language header as fallback
|
||||
* @return string
|
||||
*/
|
||||
static function get_lang()
|
||||
static function get_lang($use_accept_language=false)
|
||||
{
|
||||
if (isset($_POST['ConfigLang']))
|
||||
{
|
||||
@ -208,11 +209,25 @@ class setup
|
||||
if (!isset($_SESSION)) self::session_start();
|
||||
$ConfigLang = $_SESSION['ConfigLang'];
|
||||
}
|
||||
$matches = null;
|
||||
if ($use_accept_language && empty($ConfigLang) &&
|
||||
preg_match_all('/(^|,)([a-z-]+)/', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']), $matches))
|
||||
{
|
||||
$available = Api\Translation::get_available_langs(false);
|
||||
foreach($matches[2] as $lang)
|
||||
{
|
||||
if (isset($available[$lang]))
|
||||
{
|
||||
$ConfigLang = $lang;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$ConfigLang))
|
||||
{
|
||||
$ConfigLang = null; // not returning 'en', as it suppresses the language selection in check_install and manageheader
|
||||
}
|
||||
//error_log(__METHOD__."() \$_POST['ConfigLang']=".array2string($_POST['ConfigLang']).", \$_SESSION['ConfigLang']=".array2string($_SESSION['ConfigLang'])." returning ".array2string($ConfigLang));
|
||||
//error_log(__METHOD__."() \$_POST['ConfigLang']=".array2string($_POST['ConfigLang']).", \$_SESSION['ConfigLang']=".array2string($_SESSION['ConfigLang']).", HTTP_ACCEPT_LANGUAGE=$_SERVER[HTTP_ACCEPT_LANGUAGE] --> returning ".array2string($ConfigLang));
|
||||
return $ConfigLang;
|
||||
}
|
||||
|
||||
|
@ -286,8 +286,7 @@ class setup_html
|
||||
{
|
||||
if (empty($ConfigLang))
|
||||
{
|
||||
$ConfigLang = setup::get_lang();
|
||||
if (empty($ConfigLang)) $ConfigLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
|
||||
$ConfigLang = setup::get_lang(true); // true use Accept-Language header
|
||||
}
|
||||
return Api\Html::select('ConfigLang', $ConfigLang, Api\Translation::get_available_langs(false), true,
|
||||
$onChange ? ' onchange="this.form.submit();"' : '');
|
||||
|
@ -43,7 +43,7 @@ class setup_translation
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$ConfigLang = setup::get_lang();
|
||||
$ConfigLang = setup::get_lang(true);
|
||||
|
||||
if(!$ConfigLang)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user