Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
server: Update locale when switching language from settings
Elian Doran9f6f0f5d60c3
diff --git a/src/routes/api/options.ts b/src/routes/api/options.tsindex 8f4f661ffb..1cd2457636 100644--- a/src/routes/api/options.ts+++ b/src/routes/api/options.ts@@ -5,6 +5,7 @@ import log from "../../services/log.js";import searchService from "../../services/search/services/search.js";import ValidationError from "../../errors/validation_error.js";import { Request } from 'express';+import { changeLanguage } from "../../services/i18n.js";// options allowed to be updated directly in the Options dialogconst ALLOWED_OPTIONS = new Set([@@ -108,6 +109,11 @@ function update(name: string, value: string) {optionService.setOption(name, value);+ if (name === "locale") {+ // This runs asynchronously, so it's not perfect, but it does the trick for now.+ changeLanguage(value);+ }+return true;}diff --git a/src/services/i18n.ts b/src/services/i18n.tsindex 3498045bd2..84a707b89c 100644--- a/src/services/i18n.ts+++ b/src/services/i18n.ts@@ -41,4 +41,8 @@ function getCurrentLanguage() {}return language;-}\ No newline at end of file+}++export function changeLanguage(locale: string) {+ return i18next.changeLanguage(locale);+}