Refactored i18n configuration, replacing `DEFAULT_LOCALE` with `DEFAULT_LOCALE_FALLBACK` and enhancing environment-based locale validation. Improved cookie persistence for cart and wishlist, ensuring fallback handling for unauthenticated users. Enhancements: - Added `createProjectKey` utility for consistent project key generation. - Reworked cart and wishlist composables (`useOrderOverwrite`, `useWishlistOverwrite`) to decouple product identifier and handle cookies robustly. - Centralized `DEFAULT_LOCALE` logic for better maintainability. - Refined `useOrderSync` and `useWishlistSync` for clean synchronization across auth states. - Updated SCSS in hero and header styles for alignment corrections. Breaking Changes: `DEFAULT_LOCALE` constant removed; replaced with runtime config and fallback logic. Consumers must adapt to `DEFAULT_LOCALE_FALLBACK` and `$appHelpers.DEFAULT_LOCALE`.
36 lines
868 B
TypeScript
36 lines
868 B
TypeScript
import type { ILanguage } from '@types';
|
|
|
|
export const useLanguageStore = defineStore('language', () => {
|
|
const { $appHelpers } = useNuxtApp();
|
|
|
|
const cookieLocale = useCookie($appHelpers.COOKIES_LOCALE_KEY, {
|
|
default: () => $appHelpers.DEFAULT_LOCALE,
|
|
path: '/',
|
|
});
|
|
|
|
const localeFromCookies = computed(() => cookieLocale.value);
|
|
|
|
const languages = ref<ILanguage[] | null>(null);
|
|
const setLanguages = (payload: ILanguage[]) => {
|
|
languages.value = payload;
|
|
};
|
|
|
|
const currentLocale = ref<ILanguage | null>(null);
|
|
const setCurrentLocale = (payload: ILanguage | null) => {
|
|
currentLocale.value = payload;
|
|
};
|
|
|
|
watch(
|
|
() => localeFromCookies.value,
|
|
() => {
|
|
setCurrentLocale(languages.value?.find((l) => l.code === localeFromCookies.value) as ILanguage);
|
|
},
|
|
);
|
|
|
|
return {
|
|
languages,
|
|
setLanguages,
|
|
currentLocale,
|
|
setCurrentLocale,
|
|
};
|
|
});
|