client: Add language switcher in settings

This commit is contained in:
Elian Doran 2024-08-11 07:46:27 +03:00
parent 51afb63e25
commit bc648e981e
No known key found for this signature in database
3 changed files with 43 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import DatabaseAnonymizationOptions from "./options/advanced/database_anonymizat
import BackendLogWidget from "./content/backend_log.js"; import BackendLogWidget from "./content/backend_log.js";
import AttachmentErasureTimeoutOptions from "./options/other/attachment_erasure_timeout.js"; import AttachmentErasureTimeoutOptions from "./options/other/attachment_erasure_timeout.js";
import RibbonOptions from "./options/appearance/ribbon.js"; import RibbonOptions from "./options/appearance/ribbon.js";
import LocalizationOptions from "./options/appearance/i18n.js";
const TPL = `<div class="note-detail-content-widget note-detail-printable"> const TPL = `<div class="note-detail-content-widget note-detail-printable">
<style> <style>
@ -54,6 +55,7 @@ const TPL = `<div class="note-detail-content-widget note-detail-printable">
const CONTENT_WIDGETS = { const CONTENT_WIDGETS = {
_optionsAppearance: [ _optionsAppearance: [
LocalizationOptions,
ThemeOptions, ThemeOptions,
FontsOptions, FontsOptions,
ZoomFactorOptions, ZoomFactorOptions,

View File

@ -0,0 +1,39 @@
import OptionsWidget from "../options_widget.js";
import server from "../../../../services/server.js";
import utils from "../../../../services/utils.js";
const TPL = `
<div class="options-section">
<h4>Localization</h4>
<div class="form-group row">
<div class="col-6">
<label>Language</label>
<select class="locale-select form-control"></select>
</div>
</div>
</div>
`;
export default class LocalizationOptions extends OptionsWidget {
doRender() {
this.$widget = $(TPL);
this.$localeSelect = this.$widget.find(".locale-select");
this.$localeSelect.on("change", async() => {
const newLocale = this.$localeSelect.val();
await server.put(`options/locale/${newLocale}`);
utils.reloadFrontendApp("locale change");
});
}
async optionsLoaded(options) {
const availableLocales = await server.get("options/locales");
for (const locale of availableLocales) {
this.$localeSelect.append($("<option>")
.attr("value", locale.id)
.text(locale.name));
}
this.$localeSelect.val(options.locale);
}
}

View File

@ -58,7 +58,8 @@ const ALLOWED_OPTIONS = new Set([
'customSearchEngineName', 'customSearchEngineName',
'customSearchEngineUrl', 'customSearchEngineUrl',
'promotedAttributesOpenInRibbon', 'promotedAttributesOpenInRibbon',
'editedNotesOpenInRibbon' 'editedNotesOpenInRibbon',
'locale'
]); ]);
function getOptions() { function getOptions() {