Created centralized helpers: - src/lib/i18n/pageMetadata.ts: All page metadata (titles, descriptions, alt text) - src/lib/i18n/productText.ts: Product-specific translated text (shortDescription, benefits) - src/lib/i18n/metadata.ts: Helper functions for locale handling Updated all pages to use centralized metadata: - Homepage: Uses getPageMetadata for title, description, productionAlt - Products page: Uses getPageMetadata - Product detail: Uses getPageMetadata + getTranslatedShortDescription/getTranslatedBenefits - About page: Uses getPageMetadata ProductDetail component now uses: - getTranslatedShortDescription() instead of locale comparison - getTranslatedBenefits() instead of locale comparison All user-facing text now goes through translation files or centralized helpers. Adding a new language now requires only: 1. Add to SUPPORTED_LOCALES in locales.ts 2. Add LOCALE_CONFIG entry 3. Add entries to pageMetadata.ts and productText.ts 4. Add translation keys to message files
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { DEFAULT_LOCALE, LOCALE_CONFIG, SUPPORTED_LOCALES, type Locale } from "./locales";
|
|
|
|
export function getSaleorLocale(locale: Locale): string {
|
|
return LOCALE_CONFIG[locale].saleorLocale;
|
|
}
|
|
|
|
export function getLocaleLabel(locale: Locale): string {
|
|
return LOCALE_CONFIG[locale].label;
|
|
}
|
|
|
|
export function isDefaultLocale(locale: string): boolean {
|
|
return locale === DEFAULT_LOCALE;
|
|
}
|
|
|
|
export function getLocaleFromParams(params: { locale: string }): Locale {
|
|
const { locale } = params;
|
|
if (SUPPORTED_LOCALES.includes(locale as Locale)) {
|
|
return locale as Locale;
|
|
}
|
|
return DEFAULT_LOCALE;
|
|
}
|
|
|
|
export function getProductLocale(locale: Locale): string {
|
|
return getSaleorLocale(locale);
|
|
}
|
|
|
|
export function buildHreflangAlternates(baseUrl: string): Record<string, string> {
|
|
const alternates: Record<string, string> = {};
|
|
for (const loc of SUPPORTED_LOCALES) {
|
|
if (loc === DEFAULT_LOCALE) {
|
|
alternates[loc] = baseUrl;
|
|
} else {
|
|
alternates[loc] = `${baseUrl}/${loc}`;
|
|
}
|
|
}
|
|
return alternates;
|
|
}
|