Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/i18n/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)!
);
}
36 changes: 36 additions & 0 deletions tests/unit/i18n-config.test.ts
Original file line number Diff line number Diff line change
@@ -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,
});
});
Loading