refactor: eliminate hardcoded locale comparisons for antifragility
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
This commit is contained in:
98
src/lib/i18n/pageMetadata.ts
Normal file
98
src/lib/i18n/pageMetadata.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import type { Locale } from "./locales";
|
||||
|
||||
const PAGE_METADATA: Record<Locale, {
|
||||
home: { title: string; description: string; productionAlt: string };
|
||||
products: { title: string; description: string };
|
||||
productNotFound: string;
|
||||
about: { title: string; description: string; productionAlt: string };
|
||||
contact: { title: string; description: string };
|
||||
}> = {
|
||||
sr: {
|
||||
home: {
|
||||
title: "ManoonOils - Premium prirodna ulja za negu kose i kože",
|
||||
description: "Otkrijte našu premium kolekciju prirodnih ulja za negu kose i kože.",
|
||||
productionAlt: "Proizvodnja prirodnih ulja",
|
||||
},
|
||||
products: {
|
||||
title: "Proizvodi - ManoonOils",
|
||||
description: "Pregledajte našu kolekciju premium prirodnih ulja za negu kose i kože.",
|
||||
},
|
||||
productNotFound: "Proizvod nije pronađen",
|
||||
about: {
|
||||
title: "O nama - ManoonOils",
|
||||
description: "Saznajte više o ManoonOils - naša priča, misija i posvećenost prirodnoj lepoti.",
|
||||
productionAlt: "Proizvodnja prirodnih ulja",
|
||||
},
|
||||
contact: {
|
||||
title: "Kontakt - ManoonOils",
|
||||
description: "Kontaktirajte nas za sva pitanja o proizvodima, narudžbinama ili saradnji.",
|
||||
},
|
||||
},
|
||||
en: {
|
||||
home: {
|
||||
title: "ManoonOils - Premium Natural Oils for Hair & Skin",
|
||||
description: "Discover our premium collection of natural oils for hair and skin care.",
|
||||
productionAlt: "Natural oils production",
|
||||
},
|
||||
products: {
|
||||
title: "Products - ManoonOils",
|
||||
description: "Browse our collection of premium natural oils for hair and skin care.",
|
||||
},
|
||||
productNotFound: "Product not found",
|
||||
about: {
|
||||
title: "About - ManoonOils",
|
||||
description: "Learn more about ManoonOils - our story, mission, and commitment to natural beauty.",
|
||||
productionAlt: "Natural oils production",
|
||||
},
|
||||
contact: {
|
||||
title: "Contact - ManoonOils",
|
||||
description: "Contact us for any questions about products, orders, or collaborations.",
|
||||
},
|
||||
},
|
||||
de: {
|
||||
home: {
|
||||
title: "ManoonOils - Premium natürliche Öle für Haar & Haut",
|
||||
description: "Entdecken Sie unsere Premium-Kollektion natürlicher Öle für Haar- und Hautpflege.",
|
||||
productionAlt: "Natürliche Ölproduktion",
|
||||
},
|
||||
products: {
|
||||
title: "Produkte - ManoonOils",
|
||||
description: "Durchsuchen Sie unsere Kollektion premium natürlicher Öle für Haar- und Hautpflege.",
|
||||
},
|
||||
productNotFound: "Produkt nicht gefunden",
|
||||
about: {
|
||||
title: "Über uns - ManoonOils",
|
||||
description: "Erfahren Sie mehr über ManoonOils und unsere Mission, premium natürliche Produkte anzubieten.",
|
||||
productionAlt: "Natürliche Ölproduktion",
|
||||
},
|
||||
contact: {
|
||||
title: "Kontakt - ManoonOils",
|
||||
description: "Kontaktieren Sie uns für Fragen zu Produkten, Bestellungen oder Zusammenarbeit.",
|
||||
},
|
||||
},
|
||||
fr: {
|
||||
home: {
|
||||
title: "ManoonOils - Huiles Naturelles Premium pour Cheveux & Peau",
|
||||
description: "Découvrez notre collection premium d'huiles naturelles pour les soins capillaires et cutanés.",
|
||||
productionAlt: "Production d'huiles naturelles",
|
||||
},
|
||||
products: {
|
||||
title: "Produits - ManoonOils",
|
||||
description: "Parcourez notre collection d'huiles naturelles premium pour les soins capillaires et cutanés.",
|
||||
},
|
||||
productNotFound: "Produit non trouvé",
|
||||
about: {
|
||||
title: "À propos - ManoonOils",
|
||||
description: "En savoir plus sur ManoonOils et notre mission de fournir des produits naturels premium.",
|
||||
productionAlt: "Production d'huiles naturelles",
|
||||
},
|
||||
contact: {
|
||||
title: "Contact - ManoonOils",
|
||||
description: "Contactez-nous pour toute question sur les produits, commandes ou collaborations.",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export function getPageMetadata(locale: Locale) {
|
||||
return PAGE_METADATA[locale] || PAGE_METADATA.en;
|
||||
}
|
||||
Reference in New Issue
Block a user