i18n slugs fix
Some checks failed
Build & Deploy KLZ Cables / deploy (push) Failing after 17m15s

This commit is contained in:
2026-01-21 16:33:48 +01:00
parent 656852e983
commit 1d472062b1
6 changed files with 42 additions and 35 deletions

View File

@@ -10,33 +10,18 @@ export async function mapSlugToFileSlug(translatedSlug: string, _locale: string)
const t = await getTranslations('Slugs');
// Check pages
try {
const pageSlug = t.raw(`pages.${translatedSlug}`);
if (pageSlug && typeof pageSlug === 'string') {
return pageSlug;
}
} catch {
// Key doesn't exist, continue
if (t.has(`pages.${translatedSlug}`)) {
return t(`pages.${translatedSlug}`);
}
// Check products
try {
const productSlug = t.raw(`products.${translatedSlug}`);
if (productSlug && typeof productSlug === 'string') {
return productSlug;
}
} catch {
// Key doesn't exist, continue
if (t.has(`products.${translatedSlug}`)) {
return t(`products.${translatedSlug}`);
}
// Check categories
try {
const categorySlug = t.raw(`categories.${translatedSlug}`);
if (categorySlug && typeof categorySlug === 'string') {
return categorySlug;
}
} catch {
// Key doesn't exist, continue
if (t.has(`categories.${translatedSlug}`)) {
return t(`categories.${translatedSlug}`);
}
// Return original slug if no mapping found
@@ -56,7 +41,7 @@ export async function mapFileSlugToTranslated(fileSlug: string, _locale: string)
const sections = ['pages', 'products', 'categories'];
for (const section of sections) {
try {
if (t.has(section)) {
const sectionData = t.raw(section);
if (sectionData && typeof sectionData === 'object') {
for (const [translatedSlug, mappedSlug] of Object.entries(sectionData)) {
@@ -65,8 +50,6 @@ export async function mapFileSlugToTranslated(fileSlug: string, _locale: string)
}
}
}
} catch {
// Section doesn't exist, continue
}
}
@@ -83,13 +66,11 @@ export async function mapFileSlugToTranslated(fileSlug: string, _locale: string)
export async function getSlugMappings(section: 'pages' | 'products' | 'categories', _locale: string): Promise<Record<string, string>> {
const t = await getTranslations('Slugs');
try {
if (t.has(section)) {
const sectionData = t.raw(section);
if (sectionData && typeof (sectionData as any) === 'object') {
return sectionData as Record<string, string>;
}
} catch {
// Section doesn't exist
}
return {};