From 9f6f0f5d60c3574dbf967c8adf7b56b211a8ba25 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 23 Oct 2024 19:56:06 +0300 Subject: [PATCH] server: Update locale when switching language from settings --- src/routes/api/options.ts | 6 ++++++ src/services/i18n.ts | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/routes/api/options.ts b/src/routes/api/options.ts index 8f4f661ff..1cd245763 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 dialog const 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.ts index 3498045bd..84a707b89 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); +}