feat(i18n): deprecate Spanish language support in the frontend
This commit is contained in:
@@ -1,31 +1,38 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { useSessionStorage } from '@vueuse/core'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { defineStore } from 'pinia';
|
||||
import { useSessionStorage } from '@vueuse/core';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
export const useLanguageStore = defineStore(
|
||||
'language',
|
||||
() => {
|
||||
// Initialize with the stored value or default to 'fr'
|
||||
const storedLocale = useSessionStorage('user-locale', 'fr')
|
||||
|
||||
// Get i18n instance
|
||||
const { locale } = useI18n()
|
||||
|
||||
// Set the initial locale from storage
|
||||
if (locale && storedLocale.value) {
|
||||
locale.value = storedLocale.value
|
||||
}
|
||||
|
||||
function setLocale(newLocale) {
|
||||
if (locale) {
|
||||
locale.value = newLocale
|
||||
}
|
||||
storedLocale.value = newLocale
|
||||
}
|
||||
|
||||
return {
|
||||
locale: storedLocale,
|
||||
setLocale
|
||||
}
|
||||
const ALLOWED_LOCALES = ['en', 'fr'];
|
||||
const DEFAULT_LOCALE = 'fr';
|
||||
|
||||
export const useLanguageStore = defineStore('language', () => {
|
||||
const storedLocale = useSessionStorage('user-locale', DEFAULT_LOCALE);
|
||||
|
||||
// Get i18n instance (provided globally)
|
||||
const { locale } = useI18n();
|
||||
|
||||
function sanitizeLocale(value) {
|
||||
return ALLOWED_LOCALES.includes(value) ? value : DEFAULT_LOCALE;
|
||||
}
|
||||
)
|
||||
|
||||
// Initialize locale with a sanitized value
|
||||
const initial = sanitizeLocale(storedLocale.value);
|
||||
storedLocale.value = initial;
|
||||
if (locale) {
|
||||
locale.value = initial;
|
||||
}
|
||||
|
||||
function setLocale(newLocale) {
|
||||
const next = sanitizeLocale(newLocale);
|
||||
if (locale) {
|
||||
locale.value = next;
|
||||
}
|
||||
storedLocale.value = next;
|
||||
}
|
||||
|
||||
return {
|
||||
locale: storedLocale,
|
||||
setLocale,
|
||||
allowedLocales: ALLOWED_LOCALES,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user