25 lines
814 B
JavaScript
25 lines
814 B
JavaScript
|
|
import Cookies from 'js-cookie'
|
||
|
|
|
||
|
|
import { useEmojiStore } from 'src/stores/emoji.js'
|
||
|
|
import { useI18nStore } from 'src/stores/i18n.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') {
|
||
|
|
store.$onAction(({ name, args }) => {
|
||
|
|
const { path, value } = args[0]
|
||
|
|
if (name === 'setPreference' && path === 'simple.interfaceLanguage') {
|
||
|
|
messages.setLanguage(useI18nStore().i18n, value)
|
||
|
|
useEmojiStore().loadUnicodeEmojiData(value)
|
||
|
|
Cookies.set(
|
||
|
|
BACKEND_LANGUAGE_COOKIE_NAME,
|
||
|
|
localeService.internalToBackendLocaleMulti(value),
|
||
|
|
)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|