okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-clean-7 (045843071): the app loads screens, languages, Prism and Time-skip on first use; main chunk 3,123,528 -> 755,418 B, start screen 248.5 -> 143.4 ms (p2006 Chrome, median of 10); nothing users see changes (cleanup step 7)1631a9fde

main
2.8 KiB46 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { readFile } from 'node:fs/promises';
4import { build } from 'esbuild';
5
6const languages = ['en', 'zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr'];
7const catalogs = Object.fromEntries(await Promise.all(languages.map(async l => [l, JSON.parse(await readFile(`src/locales/tune-${l}.json`, 'utf8'))])));
8const main = JSON.parse(await readFile('src/locales/en.json', 'utf8'));
9const slots = text => [...text.matchAll(/\{\d+\}/g)].map(m => m[0]).sort();
10const compiled = await build({ stdin: { contents: "export * from './src/lib/i18n';", resolveDir: process.cwd() }, bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json' } });
11const { tr, setTranslationLanguage, loadCatalog } = await import(`data:text/javascript;base64,${Buffer.from(compiled.outputFiles[0].text).toString('base64')}`);
12for (const l of ['zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr']) await loadCatalog(l);  // the non-English catalogs load on first use (src/lib/i18n.ts loadCatalog); load them before the first tr()
13
14test('the Tune dialog strings exist in every language with the same slots and no empty text', () => {
15  for (const l of languages) {
16    assert.deepEqual(Object.keys(catalogs[l]), Object.keys(catalogs.en), l);
17    for (const [id, source] of Object.entries(catalogs.en)) {
18      assert.ok(catalogs[l][id].trim(), `${l}:${id} is empty`);
19      assert.deepEqual(slots(catalogs[l][id]), slots(source), `${l}:${id}`);
20    }
21  }
22});
23
24test('the Tune strings do not collide with the main catalog ids or texts, and translate through tr()', () => {
25  const mainTexts = new Set(Object.values(main));
26  for (const [id, text] of Object.entries(catalogs.en)) {
27    assert.ok(!(id in main), id);
28    assert.ok(!mainTexts.has(text), `already in the main catalog: ${text}`);
29  }
30  setTranslationLanguage('de');
31  assert.equal(tr('Tune this model'), catalogs.de.tune01);
32  assert.equal(tr('about {0} min left', [7]), catalogs.de.tune03.replace('{0}', '7'));
33  assert.equal(tr("+{0}% faster answers, saved as '{1}'", [12, 'IQ3_S 128K']), catalogs.de.tune10.replace('{0}', '12').replace('{1}', 'IQ3_S 128K'));
34  setTranslationLanguage('en');
35  assert.equal(tr('Tune this model'), 'Tune this model');
36});
37
38test('the Tune dialog shows the answer-changing switch in plain words, off by default, in the simple dialog', async () => {
39  const source = await readFile('src/components/NativeTune.tsx', 'utf8');
40  const label = 'Allow settings that change answers very slightly (same quality)';
41  assert.ok(Object.values(catalogs.en).includes(label), 'the label is in the catalogs');
42  assert.ok(source.includes(`tr("${label}")`));
43  assert.match(source, /\[allowSmall, setAllowSmall\] = useState\(false\)/);
44  assert.match(source, /type="checkbox" checked=\{allowSmall\}/);
45  assert.match(source, /allowSmallDifferences: allowSmall/);
46});