From 39592420e46ffa7243bb8ed21fd4f25b308d2ab3 Mon Sep 17 00:00:00 2001 From: KooshaPari <42529354+KooshaPari@users.noreply.github.com> Date: Sun, 21 Jun 2026 07:58:33 -0700 Subject: [PATCH] chore(i18n): remove unused config helpers (#4482) Removes dead exports DOCS_TARGET_LOCALES and getLanguage (zero callers, Knip-reported) and adds config-adapter coverage test. Integrated into release/v3.8.33. --- src/i18n/config.ts | 14 ------------- tests/unit/i18n-config.test.ts | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 tests/unit/i18n-config.test.ts diff --git a/src/i18n/config.ts b/src/i18n/config.ts index e4d5e3edc2..70f35db9ac 100644 --- a/src/i18n/config.ts +++ b/src/i18n/config.ts @@ -52,17 +52,3 @@ export const LANGUAGES: readonly { export const RTL_LOCALES: readonly Locale[] = config.rtl as readonly Locale[]; export const LOCALE_COOKIE = "NEXT_LOCALE"; - -// Convenience helpers -------------------------------------------------------- - -/** Locales that the docs translation pipeline writes to (excludes the source). */ -export const DOCS_TARGET_LOCALES: readonly Locale[] = LANGUAGES.map((l) => l.code).filter( - (code) => !(config.docsExcluded ?? []).includes(code) -) as readonly Locale[]; - -/** Lookup by code; falls back to the default locale entry if not found. */ -export function getLanguage(code: string) { - return ( - LANGUAGES.find((l) => l.code === code) ?? LANGUAGES.find((l) => l.code === DEFAULT_LOCALE)! - ); -} diff --git a/tests/unit/i18n-config.test.ts b/tests/unit/i18n-config.test.ts new file mode 100644 index 0000000000..80bdd9d9d4 --- /dev/null +++ b/tests/unit/i18n-config.test.ts @@ -0,0 +1,36 @@ +import test from "node:test"; +import assert from "node:assert/strict"; + +import i18nConfig from "../../config/i18n.json" with { type: "json" }; +import { + DEFAULT_LOCALE, + LANGUAGES, + LOCALES, + LOCALE_COOKIE, + RTL_LOCALES, +} from "../../src/i18n/config.ts"; + +test("i18n config adapter reflects the JSON source of truth", () => { + assert.deepEqual( + LOCALES, + i18nConfig.locales.map((locale) => locale.code) + ); + assert.equal(DEFAULT_LOCALE, i18nConfig.default); + assert.deepEqual(RTL_LOCALES, i18nConfig.rtl); + assert.equal(LOCALE_COOKIE, "NEXT_LOCALE"); +}); + +test("i18n language metadata preserves native and English names", () => { + assert.equal(LANGUAGES.length, i18nConfig.locales.length); + + const english = LANGUAGES.find((language) => language.code === "en"); + const englishConfig = i18nConfig.locales.find((language) => language.code === "en"); + assert.deepEqual(english, { + code: "en", + label: englishConfig?.label, + name: englishConfig?.name, + native: englishConfig?.native, + english: englishConfig?.english, + flag: englishConfig?.flag, + }); +});