mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-30 17:04:20 +08:00
Bugfix: language selector didn't show current language in green
This commit is contained in:
parent
d1823af111
commit
0b8ec5c664
2 changed files with 9 additions and 37 deletions
|
@ -1,5 +1,4 @@
|
|||
import ko from 'ko';
|
||||
import { koComputable } from 'External/ko';
|
||||
|
||||
import { convertLangName } from 'Common/Translator';
|
||||
|
||||
|
@ -8,46 +7,19 @@ import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|||
export class LanguagesPopupView extends AbstractViewPopup {
|
||||
constructor() {
|
||||
super('Languages');
|
||||
|
||||
this.fLang = null;
|
||||
this.userLanguage = ko.observable('');
|
||||
|
||||
this.langs = ko.observableArray();
|
||||
|
||||
this.languages = koComputable(() => {
|
||||
const userLanguage = this.userLanguage();
|
||||
return this.langs.map(language => ({
|
||||
key: language,
|
||||
user: language === userLanguage,
|
||||
selected: ko.observable(false),
|
||||
fullName: convertLangName(language)
|
||||
}));
|
||||
});
|
||||
|
||||
this.langs.subscribe(() => this.setLanguageSelection());
|
||||
}
|
||||
|
||||
languageTooltipName(language) {
|
||||
return convertLangName(language, true);
|
||||
}
|
||||
|
||||
setLanguageSelection() {
|
||||
const currentLang = this.fLang ? ko.unwrap(this.fLang) : '';
|
||||
this.languages().forEach(item => item.selected(item.key === currentLang));
|
||||
}
|
||||
|
||||
beforeShow() {
|
||||
this.fLang = null;
|
||||
this.userLanguage('');
|
||||
|
||||
this.langs([]);
|
||||
this.languages = ko.observableArray();
|
||||
}
|
||||
|
||||
onShow(fLanguage, langs, userLanguage) {
|
||||
this.fLang = fLanguage;
|
||||
this.userLanguage(userLanguage || '');
|
||||
|
||||
this.langs(langs);
|
||||
this.languages(langs.map(language => ({
|
||||
key: language,
|
||||
user: userLanguage === language,
|
||||
selected: fLanguage?.() === language,
|
||||
fullName: convertLangName(language),
|
||||
title: convertLangName(language, true)
|
||||
})));
|
||||
}
|
||||
|
||||
changeLanguage(lang) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
</header>
|
||||
<div class="modal-body" style="min-height: 150px;" data-bind="foreach: languages">
|
||||
<label data-bind="click: function () { $root.changeLanguage(key); }, css: {'selected': selected, 'user': user},
|
||||
attr: { title: $root.languageTooltipName(key) },
|
||||
attr: { title: title },
|
||||
text: fullName">
|
||||
</label>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue