From 6f3f75d9b42f302324f3dafe211e8a6d9b8ad5e5 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 13 Feb 2026 14:48:39 +0200 Subject: [PATCH] i18n This reverts commit 829018b656c52e8f8dc8bd5a9f74e83f46b71567. --- src/lib/language.js | 14 ++++++++++++++ src/stores/i18n.js | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/lib/language.js diff --git a/src/lib/language.js b/src/lib/language.js new file mode 100644 index 000000000..f8904dd07 --- /dev/null +++ b/src/lib/language.js @@ -0,0 +1,14 @@ +import { useI18nStore } from 'src/stores/i18n.js' + +export const piniaLanguagePlugin = ({ store, options }) => { + if (store.$id === 'sync_config') { + store.$onAction(({ name, args }) => { + if (name === 'setPreference') { + const { path, value } = args[0] + if (path === 'simple.interfaceLanguage') { + useI18nStore().setLanguage(value) + } + } + }) + } +} diff --git a/src/stores/i18n.js b/src/stores/i18n.js index 4e7c7c5d3..a18b1d4d2 100644 --- a/src/stores/i18n.js +++ b/src/stores/i18n.js @@ -1,5 +1,14 @@ +import Cookies from 'js-cookie' import { defineStore } from 'pinia' +import { useEmojiStore } from 'src/stores/emoji.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' + +import messages from 'src/i18n/messages' +import localeService from 'src/services/locale/locale.service.js' + +const BACKEND_LANGUAGE_COOKIE_NAME = 'userLanguage' + export const useI18nStore = defineStore('i18n', { state: () => ({ i18n: null, @@ -10,5 +19,16 @@ export const useI18nStore = defineStore('i18n', { i18n: newI18n.global, }) }, + setLanguage(originalValue) { + const value = + originalValue || useSyncConfigStore().mergedConfig.interfaceLanguage + + messages.setLanguage(this.i18n, value) + useEmojiStore().loadUnicodeEmojiData(value) + Cookies.set( + BACKEND_LANGUAGE_COOKIE_NAME, + localeService.internalToBackendLocaleMulti(value), + ) + }, }, })