Add manually authored Simplified Chinese game localization
This commit is contained in:
parent
691dc72811
commit
c578d86b1a
15 changed files with 7167 additions and 10 deletions
BIN
client/assets/localization/ChineseSimplified.woff2
Normal file
BIN
client/assets/localization/ChineseSimplified.woff2
Normal file
Binary file not shown.
|
|
@ -14,6 +14,7 @@ import catalog12 from "./vi.json";
|
|||
import catalog13 from "./it.json";
|
||||
import catalog14 from "./nl.json";
|
||||
import catalog15 from "./fa.json";
|
||||
import catalog16 from "./zh-CN.json";
|
||||
export const catalogs = {
|
||||
en: catalog0,
|
||||
de: catalog1,
|
||||
|
|
@ -31,4 +32,5 @@ export const catalogs = {
|
|||
it: catalog13,
|
||||
nl: catalog14,
|
||||
fa: catalog15,
|
||||
"zh-CN": catalog16,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -34,6 +35,9 @@ export function resolveLocale(value) {
|
|||
if (/^zh-(?:tw|hk|mo|hant)(?:-|$)/.test(tag)) {
|
||||
return "zh-TW";
|
||||
}
|
||||
if (/^zh(?:-|$)/.test(tag)) {
|
||||
return "zh-CN";
|
||||
}
|
||||
return (
|
||||
Object.keys(languages).find((locale) => locale === tag.split("-")[0]) ??
|
||||
"en"
|
||||
|
|
|
|||
2285
client/js/src/localization/zh-CN.json
Normal file
2285
client/js/src/localization/zh-CN.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -28,12 +28,14 @@ export async function setLocale(value, assets) {
|
|||
next === "fa"
|
||||
? "Arabic"
|
||||
: next === "hi"
|
||||
? "Devanagari"
|
||||
: next === "ko"
|
||||
? "Korean"
|
||||
: next === "zh-TW"
|
||||
? "Chinese"
|
||||
: "SourceSans";
|
||||
? "Devanagari"
|
||||
: next === "ko"
|
||||
? "Korean"
|
||||
: next === "zh-CN"
|
||||
? "ChineseSimplified"
|
||||
: next === "zh-TW"
|
||||
? "Chinese"
|
||||
: "SourceSans";
|
||||
const file =
|
||||
font === "SourceSans"
|
||||
? "SourceSans3-Regular.ttf"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from fontTools import subset
|
|||
from fontTools.ttLib import TTFont
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--locale', action='append', help='Only rebuild the specified locale (repeatable)')
|
||||
parser.add_argument('--catalog-dir', default='client/js/src/localization')
|
||||
parser.add_argument('--output-dir', default='client/assets/localization')
|
||||
parser.add_argument('--cjk-font', default='/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc')
|
||||
|
|
@ -15,7 +16,9 @@ args = parser.parse_args()
|
|||
root = Path(__file__).resolve().parent.parent
|
||||
output = root / args.output_dir
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
for locale, name, index in [('ko', 'Korean', 1), ('zh-TW', 'Chinese', 3), ('hi', 'Devanagari', None), ('fa', 'Arabic', None)]:
|
||||
for locale, name, index in [('ko', 'Korean', 1), ('zh-TW', 'Chinese', 3), ('zh-CN', 'ChineseSimplified', 2), ('hi', 'Devanagari', None), ('fa', 'Arabic', None)]:
|
||||
if args.locale and locale not in args.locale:
|
||||
continue
|
||||
catalog = json.loads((root / args.catalog_dir / f'{locale}.json').read_text())
|
||||
text = ''.join(catalog.values()) + ''.join(chr(i) for i in range(32, 256))
|
||||
font = TTFont(args.cjk_font, fontNumber=index) if index is not None else TTFont(args.arabic_font if locale == "fa" else args.devanagari_font)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ const locales = [
|
|||
"pt-BR",
|
||||
"ko",
|
||||
"zh-TW",
|
||||
"zh-CN",
|
||||
"vi",
|
||||
"it",
|
||||
"nl",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,11 @@ 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("zh"), "zh-CN");
|
||||
assert.equal(resolveLocale("zh-Hans-SG"), "zh-CN");
|
||||
assert.equal(resolveLocale("ZH_cn"), "zh-CN");
|
||||
assert.equal(resolveLocale("zh-HK"), "zh-TW");
|
||||
assert.equal(resolveLocale(undefined), "en");
|
||||
});
|
||||
test("dynamic values are reordered while player names stay unchanged", () => {
|
||||
|
|
|
|||
88
web-client/scripts/chinese-smoke.mjs
Normal file
88
web-client/scripts/chinese-smoke.mjs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createRequire } from 'node:module';
|
||||
import { chromium } from 'playwright';
|
||||
const engine = createRequire(import.meta.url)('../.engine/server.js');
|
||||
const state = engine.stripSecret(
|
||||
await engine.init(2, [], { civilization: 'Random' }, 'chinese-smoke', {}),
|
||||
0,
|
||||
);
|
||||
const viewerUrl = process.env.VIEWER_URL || 'https://boardgamers.space/__clash_assets__/viewer.js';
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
args: ['--use-gl=angle', '--use-angle=swiftshader'],
|
||||
});
|
||||
try {
|
||||
for (const width of [390, 1400]) {
|
||||
const page = await browser.newPage({ viewport: { width, height: 900 } });
|
||||
const errors = [],
|
||||
failed = [];
|
||||
page.on('pageerror', (e) => errors.push(e.message));
|
||||
page.on('response', (r) => {
|
||||
if (r.status() >= 400) failed.push(`${r.status()} ${r.url()}`);
|
||||
});
|
||||
await page.route('https://boardgamers.space/__chinese_check__', (route) =>
|
||||
route.fulfill({
|
||||
contentType: 'text/html',
|
||||
body: '<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div>',
|
||||
}),
|
||||
);
|
||||
if (!process.env.VIEWER_URL)
|
||||
await page.route('https://boardgamers.space/__clash_assets__/**', async (route) => {
|
||||
const path = new URL(route.request().url()).pathname.replace('/__clash_assets__/', '');
|
||||
assert(!path.includes('..'));
|
||||
const types = {
|
||||
json: 'application/json',
|
||||
wasm: 'application/wasm',
|
||||
woff2: 'font/woff2',
|
||||
js: 'text/javascript',
|
||||
css: 'text/css',
|
||||
};
|
||||
await route.fulfill({
|
||||
contentType: types[path.split('.').pop()] || 'application/octet-stream',
|
||||
body: await readFile(new URL('../dist/' + path, import.meta.url)),
|
||||
});
|
||||
});
|
||||
await page.goto('https://boardgamers.space/__chinese_check__');
|
||||
await page.addScriptTag({ url: viewerUrl });
|
||||
await page.evaluate((state) => {
|
||||
window.host = clash3d.launch('#app');
|
||||
window.readyCount = 0;
|
||||
host.on('ready', () => readyCount++);
|
||||
host.emit('preferences', { sound: false, locale: 'zh-CN' });
|
||||
host.emit('player', { index: 0 });
|
||||
host.emit('state', state);
|
||||
}, state);
|
||||
await page.waitForFunction(() => readyCount === 1);
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelector('[data-clash-locale="zh-CN"]') &&
|
||||
/[\u4e00-\u9fff]/.test(document.body.innerText),
|
||||
);
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
assert(
|
||||
await page.evaluate(() => document.fonts.check('16px "Clash ChineseSimplified"', '简体中文城市进步')),
|
||||
);
|
||||
assert(await page.locator('canvas').count());
|
||||
const geometry = await page.evaluate(() => ({
|
||||
width: innerWidth,
|
||||
scroll: document.documentElement.scrollWidth,
|
||||
}));
|
||||
assert(geometry.scroll <= geometry.width + 1, JSON.stringify(geometry));
|
||||
await page.screenshot({ path: `/tmp/clash-chinese-${width}.png` });
|
||||
await page.evaluate(() => host.emit('preferences', { sound: false, locale: 'en' }));
|
||||
await page.waitForFunction(() => document.querySelector('[data-clash-locale="en"]'));
|
||||
await page.evaluate(() => host.emit('preferences', { sound: false, locale: 'zh-Hans-SG' }));
|
||||
await page.waitForFunction(
|
||||
() =>
|
||||
document.querySelector('[data-clash-locale="zh-CN"]') &&
|
||||
/[\u4e00-\u9fff]/.test(document.body.innerText),
|
||||
);
|
||||
assert.deepEqual(errors, []);
|
||||
assert.deepEqual(failed, []);
|
||||
console.log(`${width}px: Simplified Chinese cold load, font, layout and language switching passed`);
|
||||
await page.close();
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
|
|
@ -5,6 +5,9 @@ import { createTranslator, resolveLocale } from './localization/runtime.js';
|
|||
test('resolves regional BGS language preferences', () => {
|
||||
assert.equal(resolveLocale('pt-PT'), 'pt-BR');
|
||||
assert.equal(resolveLocale('zh-Hant-HK'), 'zh-TW');
|
||||
assert.equal(resolveLocale('zh-Hans-SG'), 'zh-CN');
|
||||
assert.equal(resolveLocale('zh'), 'zh-CN');
|
||||
assert.equal(resolveLocale('ZH_cn'), 'zh-CN');
|
||||
assert.equal(resolveLocale('fr_CA'), 'fr');
|
||||
assert.equal(resolveLocale('unknown'), 'en');
|
||||
});
|
||||
|
|
|
|||
BIN
web-client/src/localization/fonts/ChineseSimplified.woff2
Normal file
BIN
web-client/src/localization/fonts/ChineseSimplified.woff2
Normal file
Binary file not shown.
|
|
@ -3,11 +3,13 @@ import arabicFont from './fonts/Arabic.woff2?url&no-inline';
|
|||
import devanagariFont from './fonts/Devanagari.woff2?url&no-inline';
|
||||
import koreanFont from './fonts/Korean.woff2?url&no-inline';
|
||||
import chineseFont from './fonts/Chinese.woff2?url&no-inline';
|
||||
import chineseSimplifiedFont from './fonts/ChineseSimplified.woff2?url&no-inline';
|
||||
const fontFaces = [
|
||||
['Arabic', arabicFont],
|
||||
['Devanagari', devanagariFont],
|
||||
['Korean', koreanFont],
|
||||
['Chinese', chineseFont],
|
||||
['ChineseSimplified', chineseSimplifiedFont],
|
||||
]
|
||||
.map(
|
||||
([name, url]) =>
|
||||
|
|
|
|||
|
|
@ -41,11 +41,14 @@
|
|||
[data-clash-locale='ko'] {
|
||||
--clash-locale-font: 'Clash Korean';
|
||||
}
|
||||
[data-clash-locale='zh-CN'] {
|
||||
--clash-locale-font: 'Clash ChineseSimplified';
|
||||
}
|
||||
[data-clash-locale='zh-TW'] {
|
||||
--clash-locale-font: 'Clash Chinese';
|
||||
}
|
||||
[data-clash-locale]:is([lang='hi'], [lang='fa'], [lang='ko'], [lang='zh-TW']),
|
||||
[data-clash-locale]:is([lang='hi'], [lang='fa'], [lang='ko'], [lang='zh-TW'])
|
||||
[data-clash-locale]:is([lang='hi'], [lang='fa'], [lang='ko'], [lang='zh-TW'], [lang='zh-CN']),
|
||||
[data-clash-locale]:is([lang='hi'], [lang='fa'], [lang='ko'], [lang='zh-TW'], [lang='zh-CN'])
|
||||
:is(h1, h2, h3, h4, h5, h6, button, input, select, textarea) {
|
||||
font-family: 'DM Sans', var(--clash-locale-font), sans-serif;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,7 @@ export function resolveLocale(value) {
|
|||
if (/^zh-(?:tw|hk|mo|hant)(?:-|$)/.test(tag)) {
|
||||
return 'zh-TW';
|
||||
}
|
||||
if (/^zh(?:-|$)/.test(tag)) return 'zh-CN';
|
||||
return Object.keys(languages).find((locale) => locale === tag.split('-')[0]) ?? 'en';
|
||||
}
|
||||
|
||||
|
|
|
|||
4758
web-client/src/localization/zh-CN.json
Normal file
4758
web-client/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