diff --git a/apps/website/src/components/legal/legalSections.test.ts b/apps/website/src/components/legal/legalSections.test.ts index e937fb49e0..719406e85b 100644 --- a/apps/website/src/components/legal/legalSections.test.ts +++ b/apps/website/src/components/legal/legalSections.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from 'vitest' +import { getRoutes } from '../../config/routes' import { hasKey, t, translationKeys } from '../../i18n/translations' const PREFIX = 'affiliate-terms' @@ -64,4 +65,12 @@ describe('affiliate terms i18n', () => { ) expect(leaks).toEqual([]) }) + + it('exposes affiliate terms at the canonical /affiliates/terms path regardless of locale', () => { + // Guards against re-introducing /zh-CN/affiliates/terms, which would + // serve an unreviewed translation of legal-reviewed copy. See the + // comment on LOCALE_INVARIANT_ROUTE_KEYS in src/config/routes.ts. + expect(getRoutes('en').affiliateTerms).toBe('/affiliates/terms') + expect(getRoutes('zh-CN').affiliateTerms).toBe('/affiliates/terms') + }) }) diff --git a/apps/website/src/config/routes.ts b/apps/website/src/config/routes.ts index 9cf70157f2..994ee654eb 100644 --- a/apps/website/src/config/routes.ts +++ b/apps/website/src/config/routes.ts @@ -20,11 +20,24 @@ const baseRoutes = { type Routes = typeof baseRoutes +// Routes that are served only at their canonical path regardless of the +// active locale. Localized variants of these routes intentionally do not +// exist, so getRoutes() must not prefix them — emitting +// /zh-CN/ would produce a dead link. +// +// affiliateTerms: legal-reviewed English-only document. See the comment +// header in src/pages/affiliates/terms.astro and the affiliate-terms i18n +// block in src/i18n/translations.ts for the reasoning. +const LOCALE_INVARIANT_ROUTE_KEYS = new Set(['affiliateTerms']) + export function getRoutes(locale: Locale = 'en'): Routes { if (locale === 'en') return baseRoutes const prefix = `/${locale}` return Object.fromEntries( - Object.entries(baseRoutes).map(([k, v]) => [k, `${prefix}${v}`]) + Object.entries(baseRoutes).map(([k, v]) => [ + k, + LOCALE_INVARIANT_ROUTE_KEYS.has(k as keyof Routes) ? v : `${prefix}${v}` + ]) ) as unknown as Routes }