mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-30 18:05:55 +01:00 
			
		
		
		
	feat(options/language): store list of languages
This commit is contained in:
		| @@ -28,15 +28,33 @@ export default class LanguageOptions extends OptionsWidget { | |||||||
|         this.$languagesContainer = this.$widget.find(".options-languages"); |         this.$languagesContainer = this.$widget.find(".options-languages"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     async save() { | ||||||
|  |         const enabledLanguages: string[] = []; | ||||||
|  |  | ||||||
|  |         this.$languagesContainer.find("input:checked").each((i, el) => { | ||||||
|  |             const languageId = $(el).attr("data-language-id"); | ||||||
|  |             if (languageId) { | ||||||
|  |                 enabledLanguages.push(languageId); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |         await this.updateOption("languages", JSON.stringify(enabledLanguages)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     async optionsLoaded(options: OptionMap) { |     async optionsLoaded(options: OptionMap) { | ||||||
|         const availableLocales = await server.get<Locale[]>("options/locales"); |         const availableLocales = await server.get<Locale[]>("options/locales"); | ||||||
|  |         const enabledLanguages = (JSON.parse(options.languages) as string[]); | ||||||
|  |  | ||||||
|         this.$languagesContainer.empty(); |         this.$languagesContainer.empty(); | ||||||
|         for (const locale of availableLocales) { |         for (const locale of availableLocales) { | ||||||
|             const checkbox = $(`<label class="tn-checkbox">`) |             const checkbox = $('<input type="checkbox" class="form-check-input">') | ||||||
|                 .append($('<input type="checkbox" class="form-check-input">')) |                 .attr("data-language-id", locale.id) | ||||||
|  |                 .prop("checked", enabledLanguages.includes(locale.id)); | ||||||
|  |             const wrapper = $(`<label class="tn-checkbox">`) | ||||||
|  |                 .append(checkbox) | ||||||
|  |                 .on("change", () => this.save()) | ||||||
|                 .append(locale.name); |                 .append(locale.name); | ||||||
|             this.$languagesContainer.append($("<li>").append(checkbox)); |             this.$languagesContainer.append($("<li>").append(wrapper)); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -71,6 +71,7 @@ const ALLOWED_OPTIONS = new Set([ | |||||||
|     "editedNotesOpenInRibbon", |     "editedNotesOpenInRibbon", | ||||||
|     "locale", |     "locale", | ||||||
|     "firstDayOfWeek", |     "firstDayOfWeek", | ||||||
|  |     "languages", | ||||||
|     "textNoteEditorType", |     "textNoteEditorType", | ||||||
|     "textNoteEditorMultilineToolbar", |     "textNoteEditorMultilineToolbar", | ||||||
|     "layoutOrientation", |     "layoutOrientation", | ||||||
|   | |||||||
| @@ -134,6 +134,7 @@ const defaultOptions: DefaultOption[] = [ | |||||||
|     // Internationalization |     // Internationalization | ||||||
|     { name: "locale", value: "en", isSynced: true }, |     { name: "locale", value: "en", isSynced: true }, | ||||||
|     { name: "firstDayOfWeek", value: "1", isSynced: true }, |     { name: "firstDayOfWeek", value: "1", isSynced: true }, | ||||||
|  |     { name: "languages", value: "[]", isSynced: true }, | ||||||
|  |  | ||||||
|     // Code block configuration |     // Code block configuration | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -71,6 +71,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi | |||||||
|     eraseUnusedAttachmentsAfterSeconds: number; |     eraseUnusedAttachmentsAfterSeconds: number; | ||||||
|     eraseUnusedAttachmentsAfterTimeScale: number; |     eraseUnusedAttachmentsAfterTimeScale: number; | ||||||
|     firstDayOfWeek: number; |     firstDayOfWeek: number; | ||||||
|  |     languages: string; | ||||||
|  |  | ||||||
|     initialized: boolean; |     initialized: boolean; | ||||||
|     isPasswordSet: boolean; |     isPasswordSet: boolean; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user