feat: add Simplified Chinese to both Gaia viewers
This commit is contained in:
parent
fb8d08ec02
commit
798acfa775
7 changed files with 4284 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/old-ui",
|
||||
"version": "1.0.26",
|
||||
"version": "1.0.27",
|
||||
"scripts": {
|
||||
"serve": "vite --port 5193",
|
||||
"build": "vite build",
|
||||
|
|
|
|||
|
|
@ -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,12 @@ 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");
|
||||
for (const tag of ["zh", "zh-CN", "zh_SG", "zh-Hans", "zh-Hans-CN"]) {
|
||||
assert.equal(resolveLocale(tag), "zh-CN");
|
||||
}
|
||||
for (const tag of ["zh-TW", "zh-Hant-CN", "zh-HK", "zh-MO"]) {
|
||||
assert.equal(resolveLocale(tag), "zh-TW");
|
||||
}
|
||||
assert.equal(resolveLocale(undefined), "en");
|
||||
});
|
||||
test("dynamic values are reordered while player names stay unchanged", () => {
|
||||
|
|
@ -61,3 +66,13 @@ test("decorative arrows and attached currency values keep their meaning", () =>
|
|||
assert.equal(t.translate("Draw →"), "Tekenen →");
|
||||
assert.equal(t.translate("Your cash: $20"), "Je geld: $20");
|
||||
});
|
||||
|
||||
test("Simplified Chinese preserves names and interpolates game messages", async () => {
|
||||
const chinese = JSON.parse(await readFile(new URL("../viewer/src/localization/zh-CN.json", import.meta.url), "utf8"));
|
||||
const translator = createTranslator({ "zh-CN": chinese }, "zh-Hans");
|
||||
translator.setNames(["Build"]);
|
||||
assert.equal(translator.translate("Build"), "Build");
|
||||
assert.equal(translator.translate("Build wins it with a bid of 12, and pays 8 VP"), "Build以12的出价获胜,并支付8分");
|
||||
assert.equal(translator.translate("Your turn - Round 3"), "轮到你了——第3轮");
|
||||
assert.equal(translator.translate("Choose your faction"), "选择你的种族");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/viewer",
|
||||
"version": "5.20.61",
|
||||
"version": "5.20.62",
|
||||
"description": "Functions to visualize the map and boards for gaia project inside html canvas",
|
||||
"contributors": [
|
||||
"coyotte508",
|
||||
|
|
|
|||
108
viewer/scripts/simplified-chinese-smoke.mjs
Normal file
108
viewer/scripts/simplified-chinese-smoke.mjs
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { createServer } from "node:http";
|
||||
import { createRequire } from "node:module";
|
||||
import { chromium } from "playwright";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const root = new URL("../../", import.meta.url);
|
||||
const catalog = JSON.parse(await readFile(new URL("../src/localization/zh-CN.json", import.meta.url), "utf8"));
|
||||
const Engine = require(process.env.GAIA_SMOKE_ENGINE || "../../engine/dist/index.js").default;
|
||||
const { lessons } = require("./tutorial-manifest.cjs");
|
||||
let old = false;
|
||||
const server = createServer(async (req, res) => {
|
||||
try {
|
||||
const path = new URL(req.url, "http://localhost").pathname;
|
||||
const directory = old ? "old-ui/dist/package/" : "viewer/dist/package/";
|
||||
const entry = old ? "old-ui" : "viewer";
|
||||
const remote = old ? process.env.GAIA_SMOKE_OLD_URL : process.env.GAIA_SMOKE_URL;
|
||||
const script = remote || `/${entry}.umd.js`;
|
||||
const style = remote ? new URL(`${entry}.css`, remote).href : `/${entry}.css`;
|
||||
if (path === "/") {
|
||||
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
||||
res.end(
|
||||
`<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="${style}"><div id="app"></div><script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.min.js"></script><script src="https://cdn.jsdelivr.net/npm/bootstrap-vue@2.23.1/dist/bootstrap-vue.min.js"></script><script src="${script}"></script>`
|
||||
);
|
||||
} else if (/^\/[a-zA-Z0-9.-]+\.(?:js|css|json|jpg)$/.test(path)) {
|
||||
res.setHeader(
|
||||
"Content-Type",
|
||||
path.endsWith(".json")
|
||||
? "application/json"
|
||||
: path.endsWith(".css")
|
||||
? "text/css"
|
||||
: path.endsWith(".jpg")
|
||||
? "image/jpeg"
|
||||
: "text/javascript"
|
||||
);
|
||||
res.end(await readFile(new URL(directory + path.slice(1), root)));
|
||||
} else res.writeHead(404).end();
|
||||
} catch (error) {
|
||||
res.writeHead(500).end(String(error));
|
||||
}
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
const browser = await chromium.launch({ executablePath: process.env.CHROMIUM_EXECUTABLE });
|
||||
const url = `http://127.0.0.1:${server.address().port}/`;
|
||||
try {
|
||||
for (const mode of [false, true]) {
|
||||
old = mode;
|
||||
for (const width of [390, 1400]) {
|
||||
const page = await browser.newPage({ viewport: { width, height: 950 } });
|
||||
const errors = [];
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
await page.goto(url);
|
||||
const state = new Engine(["init 3 17"], { randomFactions: true });
|
||||
state.generateAvailableCommandsIfNeeded();
|
||||
const serialized = JSON.parse(JSON.stringify(state));
|
||||
serialized.players.forEach((player, index) => {
|
||||
player.name = ["Build", "Ada", "Bob"][index];
|
||||
});
|
||||
await page.evaluate((state) => {
|
||||
window.host = gaiaViewer.launch("#app");
|
||||
host.emit("preferences", { locale: "zh-Hans-CN", sound: false });
|
||||
host.emit("player", { index: 0 });
|
||||
host.emit("state", state);
|
||||
}, serialized);
|
||||
await page.waitForFunction(() => document.querySelector("[data-gaia-locale]")?.getAttribute("lang") === "zh-CN");
|
||||
await page.waitForFunction(
|
||||
() => document.body.textContent.includes("种族") || document.body.textContent.includes("矿场")
|
||||
);
|
||||
assert.ok((await page.locator("body").innerText()).includes("Build"), "player name stays unchanged");
|
||||
await page.evaluate(() => host.emit("preferences", { locale: "zh-Hant", sound: false }));
|
||||
await page.waitForFunction(() => document.querySelector("[data-gaia-locale]")?.getAttribute("lang") === "zh-TW");
|
||||
await page.evaluate(() => host.emit("preferences", { locale: "zh-SG", sound: false }));
|
||||
await page.waitForFunction(() => document.querySelector("[data-gaia-locale]")?.getAttribute("lang") === "zh-CN");
|
||||
assert.deepEqual(errors, []);
|
||||
await page.screenshot({ path: `/tmp/gaia-zh-CN-${old ? "old" : "modern"}-${width}.png`, fullPage: true });
|
||||
await page.close();
|
||||
console.log(
|
||||
`PASS ${old ? "classic" : "modern"} Chinese viewer, CDN Vue, language switching and names at ${width}px`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!process.env.GAIA_SMOKE_ENGINE) {
|
||||
old = false;
|
||||
for (const lesson of lessons) {
|
||||
const page = await browser.newPage({ viewport: { width: 390, height: 950 } });
|
||||
await page.goto(url);
|
||||
await page.evaluate(
|
||||
(chapter) =>
|
||||
gaiaViewer.launchTutorial("#app", { chapter, locale: "zh-CN", onProgress: (p) => (window.progress = p) }),
|
||||
lesson.id
|
||||
);
|
||||
await page.waitForFunction(() => window.progress?.step === 0);
|
||||
const expected = catalog[lesson.steps[0].title];
|
||||
assert.ok(expected, lesson.id);
|
||||
await page.waitForFunction(
|
||||
(expected) => document.querySelector(".bgs-tutorial-heading")?.textContent.includes(expected),
|
||||
expected
|
||||
);
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth + 2), false, lesson.id);
|
||||
await page.close();
|
||||
}
|
||||
console.log(`PASS Chinese opening titles and mobile layout for all ${lessons.length} tutorials`);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
|
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
|
|||
4135
viewer/src/localization/zh-CN.json
Normal file
4135
viewer/src/localization/zh-CN.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue