mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-01 04:22:15 +08:00
Language popup otimizations
This commit is contained in:
parent
d0efae7d35
commit
9bec1d0a8f
6 changed files with 109 additions and 23 deletions
|
@ -4,6 +4,7 @@
|
|||
'use strict';
|
||||
|
||||
var
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
|
||||
Utils = require('Common/Utils'),
|
||||
|
@ -17,6 +18,7 @@
|
|||
function LanguageStore()
|
||||
{
|
||||
this.languages = ko.observableArray([]);
|
||||
this.languagesTop = ko.observableArray([]);
|
||||
|
||||
this.language = ko.observable('')
|
||||
.extend({'limitedList': this.languages});
|
||||
|
@ -24,9 +26,14 @@
|
|||
|
||||
LanguageStore.prototype.populate = function ()
|
||||
{
|
||||
var aLanguages = Settings.settingsGet('Languages');
|
||||
var
|
||||
aLanguages = Settings.settingsGet('Languages'),
|
||||
aLanguagesTop = Settings.settingsGet('LanguagesTop')
|
||||
;
|
||||
|
||||
this.languages(Utils.isArray(aLanguages) ? aLanguages : []);
|
||||
this.languagesTop(Utils.isArray(aLanguagesTop) ? aLanguagesTop : []);
|
||||
|
||||
this.language(Settings.settingsGet('Language'));
|
||||
};
|
||||
|
||||
|
|
|
@ -35,6 +35,38 @@
|
|||
});
|
||||
}, this);
|
||||
|
||||
this.languagesTop = ko.computed(function () {
|
||||
|
||||
var
|
||||
aTop = this.LanguageStore.languagesTop(),
|
||||
aLangs = this.languages()
|
||||
;
|
||||
|
||||
return 0 < aTop.length ? _.compact(_.map(aTop, function (sLang) {
|
||||
return _.find(aLangs, function (aItem) {
|
||||
return aItem && sLang === aItem.key;
|
||||
});
|
||||
})) : [];
|
||||
}, this);
|
||||
|
||||
this.languagesBottom = ko.computed(function () {
|
||||
|
||||
var
|
||||
aTop = this.languagesTop(),
|
||||
aLangs = this.languages()
|
||||
;
|
||||
|
||||
if (0 < aTop.length)
|
||||
{
|
||||
return _.filter(aLangs, function (aItem) {
|
||||
return -1 === Utils.inArray(aItem, aTop);
|
||||
});
|
||||
}
|
||||
|
||||
return aLangs;
|
||||
|
||||
}, this);
|
||||
|
||||
this.LanguageStore.language.subscribe(function () {
|
||||
this.resetMainLanguage();
|
||||
}, this);
|
||||
|
|
|
@ -1550,6 +1550,7 @@ class Actions
|
|||
|
||||
$aResult['Themes'] = $this->GetThemes();
|
||||
$aResult['Languages'] = $this->GetLanguages();
|
||||
$aResult['LanguagesTop'] = $this->GetLanguagesTop();
|
||||
$aResult['AllowLanguagesOnSettings'] = (bool) $oConfig->Get('webmail', 'allow_languages_on_settings', true);
|
||||
$aResult['AllowLanguagesOnLogin'] = (bool) $oConfig->Get('login', 'allow_languages_on_login', true);
|
||||
$aResult['AttachmentLimit'] = ((int) $oConfig->Get('webmail', 'attachment_size_limit', 10)) * 1024 * 1024;
|
||||
|
@ -1693,16 +1694,29 @@ class Actions
|
|||
return $aResult;
|
||||
}
|
||||
|
||||
private function detectUserLanguage()
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getUserLanguageFromHeader()
|
||||
{
|
||||
$sLang = '';
|
||||
$sAcceptLang = $this->Http()->GetServer('HTTP_ACCEPT_LANGUAGE', 'en');
|
||||
if (false !== \strpos($sAcceptLang, ','))
|
||||
{
|
||||
$aParts = \explode(',', $sAcceptLang, 2);
|
||||
$sLang = !empty($aParts[0]) ? \strtolower($aParts[0]) : '';
|
||||
$sLang = !empty($aParts[0]) ? \trim(\strtolower($aParts[0])) : '';
|
||||
}
|
||||
|
||||
return $sLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function detectUserLanguage()
|
||||
{
|
||||
$sLang = $this->getUserLanguageFromHeader();
|
||||
|
||||
if (!empty($sLang))
|
||||
{
|
||||
$sLang = \preg_replace('/[^a-zA-Z0-9]+/', '-', $sLang);
|
||||
|
@ -8384,8 +8398,8 @@ class Actions
|
|||
return $aCache;
|
||||
}
|
||||
|
||||
$bEn = false;
|
||||
$sList = array();
|
||||
$aList = array();
|
||||
|
||||
$sDir = APP_VERSION_ROOT_PATH.'langs/';
|
||||
if (@\is_dir($sDir))
|
||||
{
|
||||
|
@ -8399,14 +8413,7 @@ class Actions
|
|||
$sLang = \strtolower(\substr($sFile, 0, -4));
|
||||
if (0 < \strlen($sLang) && 'always' !== $sLang)
|
||||
{
|
||||
if (\in_array($sLang, array('en')))
|
||||
{
|
||||
$bEn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
\array_push($sList, $sLang);
|
||||
}
|
||||
\array_push($aList, $sLang);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8415,14 +8422,41 @@ class Actions
|
|||
}
|
||||
}
|
||||
|
||||
\sort($sList);
|
||||
if ($bEn)
|
||||
\sort($aList);
|
||||
|
||||
$aCache = $aList;
|
||||
return $aCache;
|
||||
}
|
||||
|
||||
public function GetLanguagesTop()
|
||||
{
|
||||
$sUserLang = $this->getUserLanguageFromHeader();
|
||||
if (2 < \strlen($sUserLang))
|
||||
{
|
||||
\array_unshift($sList, 'en');
|
||||
$sUserLang = \substr($sUserLang, 0, 2);
|
||||
}
|
||||
|
||||
$aCache = $sList;
|
||||
return $sList;
|
||||
$self = $this;
|
||||
$aResult = array();
|
||||
|
||||
foreach ($this->GetLanguages() as $sLang)
|
||||
{
|
||||
if ($sUserLang === \substr($sLang, 0, 2))
|
||||
{
|
||||
$aResult[] = $sLang;
|
||||
}
|
||||
}
|
||||
|
||||
$aTopLangs = \array_map('trim', \explode(',', $this->Config()->Get('labs', 'top_langs', 'en')));
|
||||
|
||||
$aResult = \array_merge($aResult, $aTopLangs);
|
||||
$aResult = \array_unique($aResult);
|
||||
|
||||
$aResult = \array_values(\array_filter($aResult, function ($sLang) use ($self) {
|
||||
return $sLang === $self->ValidateLanguage($sLang);
|
||||
}));
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -299,6 +299,7 @@ Enables caching in the system'),
|
|||
'sieve_utf8_folder_name' => array(true),
|
||||
'curl_proxy' => array(''),
|
||||
'curl_proxy_auth' => array(''),
|
||||
'top_langs' => array('en'),
|
||||
'in_iframe' => array(false),
|
||||
'force_https' => array(false),
|
||||
'custom_login_link' => array(''),
|
||||
|
|
|
@ -366,10 +366,10 @@ class Utils
|
|||
*/
|
||||
public static function CustomParseIniFile($sFileName, $bProcessSections = false)
|
||||
{
|
||||
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('parse_ini_file'))
|
||||
{
|
||||
return @\parse_ini_file($sFileName, !!$bProcessSections);
|
||||
}
|
||||
// if (\MailSo\Base\Utils::FunctionExistsAndEnabled('parse_ini_file'))
|
||||
// {
|
||||
// return @\parse_ini_file($sFileName, !!$bProcessSections);
|
||||
// }
|
||||
|
||||
$sData = @\file_get_contents($sFileName);
|
||||
return \is_string($sData) ? @\parse_ini_string($sData, !!$bProcessSections) : null;
|
||||
|
|
|
@ -7,7 +7,19 @@
|
|||
</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div data-bind="foreach: languages">
|
||||
<div data-bind="foreach: languagesTop, visible: 0 < languagesTop().length">
|
||||
<label class="lang-item" data-tooltip-i18n="off" data-tooltip-placement="left" data-bind="click: function () { $root.changeLanguage(key); }, css: {'selected': selected},
|
||||
tooltip: function () { return $root.languageEnName(key); }">
|
||||
<span class="flag-wrapper">
|
||||
<span data-bind="css: 'flag flag-' + key" style=""></span>
|
||||
</span>
|
||||
<span class="lang-name" data-bind="text: fullName"></span>
|
||||
<i class="icon-ok pull-right" style="color: green; margin-top: 3px;"
|
||||
data-bind="visible: selected"></i>
|
||||
</label>
|
||||
</div>
|
||||
<hr data-bind="visible: 0 < languagesTop().length" />
|
||||
<div data-bind="foreach: languagesBottom">
|
||||
<label class="lang-item" data-tooltip-i18n="off" data-tooltip-placement="left" data-bind="click: function () { $root.changeLanguage(key); }, css: {'selected': selected},
|
||||
tooltip: function () { return $root.languageEnName(key); }">
|
||||
<span class="flag-wrapper">
|
||||
|
|
Loading…
Reference in a new issue