mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
Cleaner language detection
This commit is contained in:
parent
a4724df69e
commit
66d9300b61
2 changed files with 15 additions and 30 deletions
|
|
@ -621,7 +621,6 @@ class Actions
|
|||
'allowLanguagesOnLogin' => (bool) $oConfig->Get('login', 'allow_languages_on_login', true)
|
||||
);
|
||||
|
||||
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
||||
$UserLanguageRaw = $this->detectUserLanguage($bAdmin);
|
||||
|
||||
if ($bAdmin) {
|
||||
|
|
@ -746,10 +745,6 @@ class Actions
|
|||
}
|
||||
}
|
||||
|
||||
if ($oConfig->Get('login', 'determine_user_language', true)) {
|
||||
$sLanguage = $this->ValidateLanguage($UserLanguageRaw, $sLanguage, false);
|
||||
}
|
||||
|
||||
// MainAccount or AdditionalAccount
|
||||
$aResult = \array_merge($aResult, $this->getAccountData($oAccount));
|
||||
|
||||
|
|
@ -761,9 +756,6 @@ class Actions
|
|||
$aResult[\lcfirst($key)] = $value;
|
||||
}
|
||||
*/
|
||||
if ($oConfig->Get('webmail', 'allow_languages_on_settings', true)) {
|
||||
$sLanguage = (string) $oSettings->GetConf('language', $sLanguage);
|
||||
}
|
||||
$aResult['hourCycle'] = $oSettings->GetConf('hourCycle', '');
|
||||
|
||||
if (!$oSettings->GetConf('MessagesPerPage')) {
|
||||
|
|
@ -827,10 +819,6 @@ class Actions
|
|||
// }
|
||||
}
|
||||
else {
|
||||
if ($oConfig->Get('login', 'allow_languages_on_login', true) && $oConfig->Get('login', 'determine_user_language', true)) {
|
||||
$sLanguage = $this->ValidateLanguage($UserLanguageRaw, $sLanguage, false);
|
||||
}
|
||||
|
||||
if (SNAPPYMAIL_DEV) {
|
||||
$aResult['DevEmail'] = $oConfig->Get('labs', 'dev_email', '');
|
||||
$aResult['DevPassword'] = $oConfig->Get('labs', 'dev_password', '');
|
||||
|
|
@ -864,7 +852,7 @@ class Actions
|
|||
|
||||
$aResult['Theme'] = $this->GetTheme($bAdmin);
|
||||
|
||||
$aResult['language'] = $this->ValidateLanguage($sLanguage, '', false);
|
||||
$aResult['language'] = $this->GetLanguage();
|
||||
$aResult['userLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true);
|
||||
|
||||
$aResult['PluginsLink'] = $this->oPlugins->HaveJs($bAdmin)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ trait Localization
|
|||
} else {
|
||||
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
||||
if ($oAccount = $this->getAccountFromToken(false)) {
|
||||
if ($oConfig->Get('login', 'determine_user_language', true)) {
|
||||
$sLanguage = $this->ValidateLanguage($this->detectUserLanguage($bAdmin), $sLanguage, false);
|
||||
}
|
||||
if ($oConfig->Get('webmail', 'allow_languages_on_settings', true)
|
||||
&& ($oSettings = $this->SettingsProvider()->Load($oAccount))) {
|
||||
$sLanguage = $oSettings->GetConf('language', $sLanguage);
|
||||
|
|
@ -66,26 +69,20 @@ trait Localization
|
|||
return \in_array($sResult, $aLang) ? $sResult : 'en';
|
||||
}
|
||||
|
||||
private function getUserLanguagesFromHeader(): array
|
||||
{
|
||||
$aResult = $aList = array();
|
||||
$sAcceptLang = \strtolower(\MailSo\Base\Http::GetServer('HTTP_ACCEPT_LANGUAGE', 'en'));
|
||||
if (!empty($sAcceptLang) && \preg_match_all('/([a-z]{1,8}(?:-[a-z]{1,8})?)(?:;q=([0-9.]+))?/', $sAcceptLang, $aList)) {
|
||||
$aResult = \array_combine($aList[1], $aList[2]);
|
||||
foreach ($aResult as $n => $v) {
|
||||
$aResult[$n] = $v ? $v : 1;
|
||||
}
|
||||
|
||||
\arsort($aResult, SORT_NUMERIC);
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
public function detectUserLanguage(bool $bAdmin): string
|
||||
{
|
||||
$sResult = '';
|
||||
$aLangs = $this->getUserLanguagesFromHeader();
|
||||
$aLangs = $aList = array();
|
||||
|
||||
$sAcceptLang = \strtolower(\MailSo\Base\Http::GetServer('HTTP_ACCEPT_LANGUAGE', 'en'));
|
||||
if (!empty($sAcceptLang) && \preg_match_all('/([a-z]{1,8}(?:-[a-z]{1,8})?)(?:;q=([0-9.]+))?/', $sAcceptLang, $aList)) {
|
||||
$aLangs = \array_combine($aList[1], $aList[2]);
|
||||
foreach ($aLangs as $n => $v) {
|
||||
$aLangs[$n] = $v ? $v : 1;
|
||||
}
|
||||
|
||||
\arsort($aLangs, SORT_NUMERIC);
|
||||
}
|
||||
|
||||
foreach (\array_keys($aLangs) as $sLang) {
|
||||
$sLang = $this->ValidateLanguage($sLang, '', $bAdmin, true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue