Files
magpie/internal/gui/tests/i18n-keys.test.cjs
T
yetone aff4f9f22c gui, tray, alerts, settings: magpie speaks Traditional Chinese (繁體中文) with Taiwan wording, picked on its own for a zh-TW, zh-HK or zh-Hant system
Settings → Language offers 繁體中文 beside 简体中文. On System, a
browser or OS locale of zh-TW, zh-HK, zh-MO or zh-Hant (zh_TW.UTF-8 too)
shows zh-TW; zh-CN, zh-SG and zh-Hans-HK keep Simplified. The tray menu
and quota alerts follow the same choice. Release notes fall back to
Simplified.

The zh-TW strings are generated from the zh strings with opencc
(cn→twp), then corrected to Taiwan wording: 設定, 檔案, 帳號, 伺服器,
預設, 閘道, 連接埠, 參數, 選單, 透過, 取得, 用戶端, 存取, 終端機, 「」
quotes. A quota window is 時段 and a context window stays 上下文視窗.
Number units use 萬/億, and #unitsRow is shown for zh-TW.

Verified:
- New gui-zh-tw.test.cjs, in Chromium and WebKit:
  - key parity, placeholders and tags against zh;
  - no Simplified characters;
  - the Taiwan words;
  - locale detection for each system tag;
  - <html lang>, nav labels, fmtN units, the picker;
  - Settings Language at 1000px and 440px.
  With the sysLocale zh-TW line removed, it fails. On the base assets,
  all 3 fail.
- gui-ja, gui-de and i18n-keys pass.
- go vet, and go test -tags nogui for ./internal/gui and
  ./internal/settings, pass. That includes the new zh-TW cases in
  TestTrayLang / TestTrayLabels / quota_alert_test, which fail without
  the zh-TW branches.
2026-10-08 05:00:55 +08:00

24 lines
1.0 KiB
JavaScript

// Run with Node's test runner; needs no browser. A key written twice in one
// language of i18n.js is a trap: the later one silently wins, so an edit to
// the first does nothing. Every key appears once per language.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
test("no language in i18n.js has a key twice", async () => {
const src = await fs.readFile(path.resolve(__dirname, "../assets/i18n.js"), "utf8");
const body = src.slice(0, src.indexOf("\n};"));
const twice = [];
let lang, seen;
body.split("\n").forEach((line, i) => {
const head = line.match(/^ "?([\w-]+)"?: \{/);
if (head) return void ((lang = head[1]), (seen = new Map()));
const key = line.match(/^ ("(?:[^"\\]|\\.)*")\s*:/);
if (!key || !lang) return;
if (seen.has(key[1])) twice.push(`${lang} ${key[1]}: lines ${seen.get(key[1])} and ${i + 1}`);
else seen.set(key[1], i + 1);
});
assert.deepEqual(twice, []);
});