refactor: improve locale modularity
- Added src/lib/i18n/metadata.ts with helper functions - Updated [locale]/layout.tsx to use DEFAULT_LOCALE constant - routing.ts already uses centralized SUPPORTED_LOCALES Note: For full antifragility, a larger refactor would centralize all hardcoded locale comparisons for metadata text fallbacks. Currently adding a new language requires: 1. SUPPORTED_LOCALES in locales.ts 2. LOCALE_CONFIG entry 3. Translation keys in all message files
This commit is contained in:
17
src/lib/i18n/metadata.ts
Normal file
17
src/lib/i18n/metadata.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { DEFAULT_LOCALE, LOCALE_CONFIG, type Locale } from "./locales";
|
||||
|
||||
export function getMetadataText(locale: Locale, texts: Partial<Record<Locale, string>>): string {
|
||||
return texts[locale] || texts[DEFAULT_LOCALE] || "";
|
||||
}
|
||||
|
||||
export function getSaleorLocale(locale: Locale): string {
|
||||
return LOCALE_CONFIG[locale].saleorLocale;
|
||||
}
|
||||
|
||||
export function getLocaleDisplayName(locale: Locale): string {
|
||||
return LOCALE_CONFIG[locale].label;
|
||||
}
|
||||
|
||||
export function isDefaultLocale(locale: string): boolean {
|
||||
return locale === DEFAULT_LOCALE;
|
||||
}
|
||||
Reference in New Issue
Block a user