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`.
27 lines
772 B
TypeScript
27 lines
772 B
TypeScript
import type { NuxtI18nOptions } from '@nuxtjs/i18n';
|
|
import { SUPPORTED_LOCALES } from '../app/constants';
|
|
import { createProjectKey } from "../app/utils/transliterator";
|
|
|
|
export function createI18nConfig(defaultLocaleCode?: string, projectName: string): NuxtI18nOptions {
|
|
const defaultLocale = defaultLocaleCode && SUPPORTED_LOCALES.some(l => l.code === defaultLocaleCode)
|
|
? defaultLocaleCode
|
|
: 'en-gb';
|
|
|
|
const cookieKey = `${createProjectKey(projectName)}-locale`;
|
|
|
|
return {
|
|
defaultLocale,
|
|
locales: SUPPORTED_LOCALES.map((locale) => ({
|
|
code: locale.code,
|
|
file: locale.file,
|
|
})),
|
|
lazy: true,
|
|
strategy: 'prefix',
|
|
detectBrowserLanguage: {
|
|
alwaysRedirect: true,
|
|
redirectOn: 'root',
|
|
fallbackLocale: defaultLocale,
|
|
cookieKey,
|
|
},
|
|
};
|
|
}
|