Add manually authored Simplified Chinese game UI
This commit is contained in:
parent
e7a71a3387
commit
233d17e88d
5 changed files with 1361 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ export const languages = {
|
|||
"pt-BR": "Português (Brasil)",
|
||||
ko: "한국어",
|
||||
"zh-TW": "繁體中文",
|
||||
"zh-CN": "简体中文",
|
||||
vi: "Tiếng Việt",
|
||||
it: "Italiano",
|
||||
nl: "Nederlands",
|
||||
|
|
@ -32,6 +33,9 @@ export function resolveLocale(value) {
|
|||
if (/^zh-(?:tw|hk|mo|hant)(?:-|$)/.test(tag)) {
|
||||
return "zh-TW";
|
||||
}
|
||||
if (tag === "zh" || /^zh-(?:cn|sg|hans)(?:-|$)/.test(tag)) {
|
||||
return "zh-CN";
|
||||
}
|
||||
return Object.keys(languages).find((locale) => locale === tag.split("-")[0]) ?? "en";
|
||||
}
|
||||
|
||||
|
|
|
|||
1218
packages/viewer/src/localization/zh-CN.json
Normal file
1218
packages/viewer/src/localization/zh-CN.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -7,7 +7,25 @@ if (!directory) {
|
|||
}
|
||||
const source = JSON.parse(await readFile(join(directory, "en.json"), "utf8"));
|
||||
const placeholders = (text) => [...text.matchAll(/\{\w+\}/g)].map((match) => match[0]).sort();
|
||||
const locales = ["en", "de", "fr", "pl", "ro", "el", "hi", "ru", "da", "pt-BR", "ko", "zh-TW", "vi", "it", "nl", "fa"];
|
||||
const locales = [
|
||||
"en",
|
||||
"de",
|
||||
"fr",
|
||||
"pl",
|
||||
"ro",
|
||||
"el",
|
||||
"hi",
|
||||
"ru",
|
||||
"da",
|
||||
"pt-BR",
|
||||
"ko",
|
||||
"zh-TW",
|
||||
"zh-CN",
|
||||
"vi",
|
||||
"it",
|
||||
"nl",
|
||||
"fa",
|
||||
];
|
||||
for (const locale of locales) {
|
||||
const catalog = JSON.parse(await readFile(join(directory, `${locale}.json`), "utf8"));
|
||||
assert.deepEqual(Object.keys(catalog).sort(), Object.keys(source).sort(), `${locale}: missing or extra strings`);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ test("regional language preferences select supported catalogues", () => {
|
|||
assert.equal(resolveLocale("nl-BE"), "nl");
|
||||
assert.equal(resolveLocale("pt-PT"), "pt-BR");
|
||||
assert.equal(resolveLocale("zh-Hant-TW"), "zh-TW");
|
||||
assert.equal(resolveLocale("zh-CN"), "en");
|
||||
assert.equal(resolveLocale("zh-CN"), "zh-CN");
|
||||
assert.equal(resolveLocale(undefined), "en");
|
||||
});
|
||||
test("dynamic values are reordered while player names stay unchanged", () => {
|
||||
|
|
@ -64,7 +64,24 @@ test("decorative arrows and attached currency values keep their meaning", () =>
|
|||
|
||||
test("complete card effects preserve icons and allow localized word order", async () => {
|
||||
const { localizeEffect } = await import("../packages/viewer/src/lib/localized-effect.ts");
|
||||
const locales = ["en", "fr", "de", "nl", "da", "pl", "ro", "el", "hi", "ru", "pt-BR", "ko", "zh-TW", "vi", "it"];
|
||||
const locales = [
|
||||
"en",
|
||||
"fr",
|
||||
"de",
|
||||
"nl",
|
||||
"da",
|
||||
"pl",
|
||||
"ro",
|
||||
"el",
|
||||
"hi",
|
||||
"ru",
|
||||
"pt-BR",
|
||||
"ko",
|
||||
"zh-TW",
|
||||
"zh-CN",
|
||||
"vi",
|
||||
"it",
|
||||
];
|
||||
const actual = Object.fromEntries(
|
||||
await Promise.all(
|
||||
locales.map(async (locale) => [
|
||||
|
|
@ -142,3 +159,12 @@ test("Persian regional tags select Farsi", () => {
|
|||
assert.equal(resolveLocale("fa-IR"), "fa");
|
||||
assert.equal(resolveLocale("fa_IR"), "fa");
|
||||
});
|
||||
|
||||
test("Simplified Chinese aliases preserve Traditional Chinese preferences", () => {
|
||||
for (const tag of ["zh", "zh-CN", "zh_CN", "zh-SG", "zh-Hans", "zh-Hans-CN"]) {
|
||||
assert.equal(resolveLocale(tag), "zh-CN");
|
||||
}
|
||||
for (const tag of ["zh-TW", "zh-HK", "zh-MO", "zh-Hant", "zh-Hant-CN"]) {
|
||||
assert.equal(resolveLocale(tag), "zh-TW");
|
||||
}
|
||||
});
|
||||
|
|
|
|||
92
tests/zh-cn-browser.mjs
Normal file
92
tests/zh-cn-browser.mjs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import { previewServer } from "./tutorial-preview.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import { chromium } from "playwright";
|
||||
import { initGame } from "../packages/engine/dist/index.js";
|
||||
import { stripSecret } from "../packages/engine/dist/wrapper.js";
|
||||
|
||||
const server = previewServer();
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
const base = `http://127.0.0.1:${server.address().port}`;
|
||||
const browser = await chromium.launch({ executablePath: process.env.OUTPOST_CHROMIUM_EXECUTABLE });
|
||||
try {
|
||||
for (const width of [390, 1400]) {
|
||||
const page = await browser.newPage({ viewport: { width, height: 950 } });
|
||||
const errors = [];
|
||||
const languageRequests = [];
|
||||
page.on("request", (request) => {
|
||||
if (request.url().endsWith(".json")) {
|
||||
languageRequests.push(request.url());
|
||||
}
|
||||
});
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
await page.setContent('<div id="app"></div>');
|
||||
await page.addStyleTag({ path: "packages/viewer/dist/outpost-viewer.css" });
|
||||
await page.addScriptTag({ url: base + "/bundle.js" });
|
||||
const state = initGame(3, { fastBid: true, kicker: true }, "protocol-smoke");
|
||||
state.players.forEach((player, i) => {
|
||||
player.name = ["You", "Full Name", "Other"][i];
|
||||
});
|
||||
await page.evaluate(
|
||||
(state) => {
|
||||
window.events = [];
|
||||
window.emitter = window.outpost.launch("#app");
|
||||
for (const name of [
|
||||
"ready",
|
||||
"move",
|
||||
"replaceLog",
|
||||
"fetchState",
|
||||
"replay:info",
|
||||
"player:clicked",
|
||||
"chat:read",
|
||||
"chat:send",
|
||||
"update:setting",
|
||||
]) {
|
||||
emitter.on(name, (data) => {
|
||||
structuredClone(data);
|
||||
events.push({ name, data });
|
||||
});
|
||||
}
|
||||
emitter.emit("player", { index: 0 });
|
||||
emitter.emit("preferences", { sound: false });
|
||||
emitter.emit("state", state);
|
||||
emitter.emit("chat:state", {
|
||||
canSend: true,
|
||||
mentions: [
|
||||
{ id: "u0", name: "You", playerIndex: 0 },
|
||||
{ id: "u1", name: "Full Name", playerIndex: 1 },
|
||||
],
|
||||
});
|
||||
emitter.emit(
|
||||
"chat:messages",
|
||||
Array.from({ length: 35 }, (_, i) => ({
|
||||
_id: (i + 1).toString(16).padStart(24, "0"),
|
||||
text: `History ${i}`,
|
||||
createdAt: new Date(2026, 8, i < 30 ? 12 : 13, 12).toISOString(),
|
||||
type: "text",
|
||||
author: "Other",
|
||||
playerIndex: 2,
|
||||
}))
|
||||
);
|
||||
},
|
||||
stripSecret(state, 0)
|
||||
);
|
||||
await page.waitForFunction(() => events.filter((e) => e.name === "ready").length === 1);
|
||||
await page.evaluate(() => emitter.emit("preferences", { locale: "fr", sound: false }));
|
||||
await page.waitForFunction(() => document.body.textContent.includes("Eau"));
|
||||
assert.equal(languageRequests.length, 1);
|
||||
await page.evaluate(() => emitter.emit("preferences", { locale: "zh-Hans-CN", sound: false }));
|
||||
await page.waitForFunction(() => document.body.textContent.includes("矿石"));
|
||||
assert.equal(languageRequests.length, 2);
|
||||
await page.screenshot({ path: `/tmp/outpost-zh-CN-${width}.png`, fullPage: true });
|
||||
await page.evaluate(() => emitter.emit("preferences", { locale: "en", sound: false }));
|
||||
await page.waitForFunction(() => document.body.textContent.includes("Water"));
|
||||
await page.screenshot({ path: `/tmp/outpost-resource-icons-${width}.png`, fullPage: true });
|
||||
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
console.log("Outpost Simplified Chinese: mobile/desktop lazy loading and language switching passed.");
|
||||
} finally {
|
||||
await browser.close();
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue