diff --git a/src/app/[locale]/layout.tsx b/src/app/[locale]/layout.tsx index 326e078..0f2ad3b 100644 --- a/src/app/[locale]/layout.tsx +++ b/src/app/[locale]/layout.tsx @@ -1,7 +1,7 @@ import { Metadata } from "next"; import { NextIntlClientProvider } from "next-intl"; import { getMessages, setRequestLocale } from "next-intl/server"; -import { SUPPORTED_LOCALES } from "@/lib/i18n/locales"; +import { SUPPORTED_LOCALES, DEFAULT_LOCALE, isValidLocale } from "@/lib/i18n/locales"; const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://dev.manoonoils.com"; @@ -15,11 +15,12 @@ export async function generateMetadata({ params: Promise<{ locale: string }>; }): Promise { const { locale } = await params; - const localePrefix = locale === "sr" ? "" : `/${locale}`; + const validLocale = isValidLocale(locale) ? locale : DEFAULT_LOCALE; + const localePrefix = validLocale === DEFAULT_LOCALE ? "" : `/${validLocale}`; const languages: Record = {}; for (const loc of SUPPORTED_LOCALES) { - const prefix = loc === "sr" ? "" : `/${loc}`; + const prefix = loc === DEFAULT_LOCALE ? "" : `/${loc}`; languages[loc] = `${baseUrl}${prefix}`; } diff --git a/src/lib/i18n/metadata.ts b/src/lib/i18n/metadata.ts new file mode 100644 index 0000000..ab66f2d --- /dev/null +++ b/src/lib/i18n/metadata.ts @@ -0,0 +1,17 @@ +import { DEFAULT_LOCALE, LOCALE_CONFIG, type Locale } from "./locales"; + +export function getMetadataText(locale: Locale, texts: Partial>): 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; +}