Files
youtube-generator/tests/i18n/locale-registration.test.ts
poli0981andClaude Opus 5 b920d3567e chore(release): v0.38.0 — Portuguese (Brazil) and Indonesian
Two new locales, 1,562 strings each, complete: titles, every description
block, all 248 content warnings, tech notes, playthrough notes, pinned
comments, playlist copy, and the whole interface.

Brazil is a top-three market for gameplay viewing and Indonesia the largest in
Southeast Asia. Both use Latin script, so neither needed font or layout work.

**docs/I18N.md was wrong about what registering a locale takes**, and this
release is where that bit. It claimed `SUPPORTED_LANGUAGES` was "the only
registration step". It is one of four, and they fail differently:

  SupportedLanguage union        compile error
  CORE_TAGS_BY_LANG              compile error  (there are TWO such records,
  MULTILINGUAL_TAGS              compile error   not one — the doc mentioned one)
  detectBrowserLanguage          SILENT

The silent one matters most: the language works perfectly and simply never
auto-selects for a visitor whose browser is set to it. `SUPPORTED_LANGUAGES`
also wasn't type-bound to the union, and every consumer casts, so a mismatch
between the first two compiled cleanly — it now carries a `satisfies` clause.

`tests/i18n/locale-registration.test.ts` exists to close those gaps: it checks
the picker list against the locale directories on disk in BOTH directions, plus
namespace files, flags, native names and tag pools.

Browser-language detection now matches the full BCP-47 tag before the bare
language, or `pt-BR` would be reduced to `pt` and never found. Any other
Portuguese variant resolves to pt-BR rather than falling through to English.

115 UI keys were not hand-translated at all: their English text is
byte-identical to a string already translated in templates.json (graphics
presets, ray-tracing modes, difficulty names, content-warning labels), so they
are copied across. Translating those twice risks a checkbox and the rendered
description disagreeing about what the same option is called.

Deliberately left in English, matching what the Spanish locale already does:
vendor product names (NVIDIA DLSS, AMD FSR, Intel XeSS, Fluid Motion Frames),
platform brands, hardware acronyms, genre terms that are loanwords in both
languages, and example URLs/emails in placeholders. So pt-BR reads 1,344/1,562
and id 1,308/1,562 "differing from English" — the remainder are those
pass-throughs, not gaps.

Both are AI-translated and NOT native-reviewed. Recorded in DISCLAIMER.md
alongside JA/ES/KO/ZH.

Also replaces `__dirname` in the Vite and Vitest configs with
`import.meta.dirname` — Vite 8's native config loader doesn't provide the CJS
global and warned on every run.

v0.36.0 is skipped: the dependency release shipped first and took 0.37.0.

Tests 692 → 698. Validator now 1,562 keys x 8 locales.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-17 12:46:54 +07:00

84 lines
3.3 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { readdirSync, existsSync } from "fs";
import { resolve, join } from "path";
import { SUPPORTED_LANGUAGES } from "@i18n/index";
import { initialSettings } from "@store/settings-heal";
import { CORE_TAGS_BY_LANG, MULTILINGUAL_TAGS } from "@engine/tag-generator";
/**
* Adding a locale means editing four separate places, and only two of them
* fail loudly on their own:
*
* 1. `SUPPORTED_LANGUAGES` (src/i18n/index.ts) — silent if missed
* 2. `SupportedLanguage` union (src/engine/types.ts) — compile error
* 3. `detectBrowserLanguage` (settings-heal.ts) — SILENT if missed
* 4. `MULTILINGUAL_TAGS` / `CORE_TAGS_BY_LANG` — compile error
*
* docs/I18N.md claimed for a long time that (1) was the only step. It isn't,
* and (3) in particular fails invisibly: the language works, and simply never
* auto-selects for a visitor whose browser is set to it.
*
* These tests close the two silent gaps by checking the picker list against
* what is actually on disk, in both directions.
*/
const LOCALES_DIR = resolve("src/i18n/locales");
function localeDirsOnDisk(): string[] {
return readdirSync(LOCALES_DIR, { withFileTypes: true })
.filter((d) => d.isDirectory())
.map((d) => d.name)
.sort();
}
describe("locale registration", () => {
it("offers exactly the locales that exist on disk", () => {
const registered = SUPPORTED_LANGUAGES.map((l) => l.id as string).sort();
expect(registered).toEqual(localeDirsOnDisk());
});
it("ships both namespaces for every registered locale", () => {
for (const { id } of SUPPORTED_LANGUAGES) {
for (const ns of ["ui", "templates"]) {
expect(existsSync(join(LOCALES_DIR, id, `${ns}.json`)), `${id}/${ns}.json`).toBe(true);
}
}
});
it("gives every registered locale a flag and a native name", () => {
for (const lang of SUPPORTED_LANGUAGES) {
expect(lang.flag, `${lang.id} flag`).toBeTruthy();
expect(lang.nativeName, `${lang.id} nativeName`).toBeTruthy();
// The native name is what the picker shows. An English label there means
// someone copied a row and forgot to translate it.
expect(lang.label, `${lang.id} label`).toBeTruthy();
}
});
it("has a tag pool for every registered locale", () => {
// Both are typed `Record<SupportedLanguage, …>` so TypeScript already
// enforces this — but only against the union, not against the picker list.
for (const { id } of SUPPORTED_LANGUAGES) {
expect(typeof CORE_TAGS_BY_LANG[id], `CORE_TAGS_BY_LANG.${id}`).toBe("function");
expect(typeof MULTILINGUAL_TAGS[id], `MULTILINGUAL_TAGS.${id}`).toBe("function");
}
});
it("produces non-empty, game-name-bearing tags for every locale", () => {
for (const { id } of SUPPORTED_LANGUAGES) {
const core = CORE_TAGS_BY_LANG[id]("Silent Hill 2");
expect(core.length, `${id} core tags`).toBeGreaterThan(0);
expect(
core.some((t) => t.includes("Silent Hill 2")),
`${id} core tags use the game name`,
).toBe(true);
}
});
it("defaults the app language to a registered locale", () => {
const registered = SUPPORTED_LANGUAGES.map((l) => l.id as string);
expect(registered).toContain(initialSettings.appLanguage);
expect(registered).toContain(initialSettings.defaultOutputLanguage);
});
});