diff --git a/scripts/check-locale.ts b/scripts/check-locale.ts index 26eeab7a..dfe392c8 100644 --- a/scripts/check-locale.ts +++ b/scripts/check-locale.ts @@ -38,11 +38,21 @@ function getExpectedTranslation( sourcePath: string, sourceLocale: string, targetLocale: string, -): string { + alternates: { hreflang: string; href: string }[], +): string | null { const segments = sourcePath.split('/').filter(Boolean); - // First segment is locale segments[0] = targetLocale; + // Blog posts have dynamic slugs. If it's a blog post, trust the alternate tag + // if the href is present in the sitemap. + // The Smoke Test's primary job is ensuring the alternate links point to valid pages. + if (segments[1] === (targetLocale === 'de' ? 'blog' : 'blog') && segments.length > 2) { + const altLink = alternates.find((a) => a.hreflang === targetLocale); + if (altLink) { + return new URL(altLink.href).pathname; + } + } + const map = sourceLocale === 'de' ? SLUG_MAP : REVERSE_SLUG_MAP; return ( @@ -50,7 +60,7 @@ function getExpectedTranslation( segments .map((seg, i) => { if (i === 0) return seg; // locale - return map[seg] || seg; // translate or keep (product names like n2x2y stay the same) + return map[seg] || seg; // translate or keep }) .join('/') ); @@ -118,7 +128,7 @@ async function main() { if (alt.hreflang === locale) continue; // Same locale, skip // 1. Check slug translation is correct - const expectedPath = getExpectedTranslation(path, locale, alt.hreflang); + const expectedPath = getExpectedTranslation(path, locale, alt.hreflang, alternates); const actualPath = new URL(alt.href).pathname; if (actualPath !== expectedPath) {