move language switch logic entirely into plugin
This commit is contained in:
parent
ea020cefdb
commit
6967151275
2 changed files with 16 additions and 19 deletions
|
|
@ -1,4 +1,11 @@
|
|||
import { useI18nStore } from 'src/stores/i18n.js'
|
||||
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 piniaLanguagePlugin = ({ store, options }) => {
|
||||
if (store.$id === 'sync_config') {
|
||||
|
|
@ -7,6 +14,15 @@ export const piniaLanguagePlugin = ({ store, options }) => {
|
|||
const { path, value } = args[0]
|
||||
if (path === 'simple.interfaceLanguage') {
|
||||
useI18nStore().setLanguage(value)
|
||||
const value =
|
||||
originalValue || useSyncConfigStore().mergedConfig.interfaceLanguage
|
||||
|
||||
messages.setLanguage(this.i18n, value)
|
||||
useEmojiStore().loadUnicodeEmojiData(value)
|
||||
Cookies.set(
|
||||
BACKEND_LANGUAGE_COOKIE_NAME,
|
||||
localeService.internalToBackendLocaleMulti(value),
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,14 +1,6 @@
|
|||
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,
|
||||
|
|
@ -19,16 +11,5 @@ 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),
|
||||
)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue