[web] Move locale logic into the settings store

This commit is contained in:
Alain Nussbaumer 2025-05-30 19:18:25 +02:00
parent fc24c2279f
commit 4dc6754726
4 changed files with 56 additions and 50 deletions

File diff suppressed because one or more lines are too long

View File

@ -65,9 +65,9 @@
} }
}, },
"node_modules/@babel/parser": { "node_modules/@babel/parser": {
"version": "7.27.3", "version": "7.27.4",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.3.tgz", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.4.tgz",
"integrity": "sha512-xyYxRj6+tLNDTWi0KCBcZ9V7yg3/lwL9DWh9Uwh/RIVlIfFidggcgxKX3GCXwCiswwcGRawBKbEg2LG/Y8eJhw==", "integrity": "sha512-BRmLHGwpUqLFR2jzx9orBuX/ABDkj2jLKOXrHDTN2aOKL+jFDDKaRNo9nyYsIl9h/UE/7lMKdDjKQQyxKKDZ7g==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@babel/types": "^7.27.3" "@babel/types": "^7.27.3"

View File

@ -175,22 +175,10 @@ export default {
computed: { computed: {
locale: { locale: {
get() { get() {
const languages = this.$i18n.availableLocales return this.settingsStore.currentLocale()
let locale = languages.find((lang) => lang === this.$i18n.locale)
const [partial] = this.$i18n.locale.split('-')
if (!locale) {
locale = languages.find((lang) => lang === partial)
}
if (!locale) {
locale = languages.forEach((lang) => lang.split('-')[0] === partial)
}
if (!locale) {
locale = this.$i18n.fallbackLocale
}
return locale
}, },
set(locale) { set(locale) {
this.$i18n.locale = locale this.settingsStore.setLocale(locale)
} }
} }
} }

View File

@ -6,6 +6,21 @@ const { t, availableLocales } = i18n.global
export const useSettingsStore = defineStore('SettingsStore', { export const useSettingsStore = defineStore('SettingsStore', {
actions: { actions: {
currentLocale() {
const languages = availableLocales
let locale = languages.find((lang) => lang === i18n.global.locale.value)
const [partial] = i18n.global.locale.value.split('-')
if (!locale) {
locale = languages.find((lang) => lang === partial)
}
if (!locale) {
locale = languages.find((lang) => lang.split('-')[0] === partial)
}
if (!locale) {
locale = i18n.global.fallbackLocale
}
return locale
},
get(categoryName, optionName) { get(categoryName, optionName) {
return ( return (
this.categories this.categories
@ -16,6 +31,9 @@ export const useSettingsStore = defineStore('SettingsStore', {
async initialise() { async initialise() {
this.$state = await settings.state() this.$state = await settings.state()
}, },
setLocale(locale) {
i18n.global.locale.value = locale
},
update(option) { update(option) {
const settingCategory = this.categories.find( const settingCategory = this.categories.find(
(category) => category.name === option.category (category) => category.name === option.category