Files
LamGC 16d8400d76
Build and WordPress integration / PHP 7.4 syntax and regression tests (push) Canceled after 0s
Build and WordPress integration / PHP 8.3 syntax and regression tests (push) Canceled after 0s
Build and WordPress integration / WordPress 6.3 / PHP 7.4 (push) Canceled after 0s
Build and WordPress integration / WordPress latest / PHP 8.2 (push) Canceled after 0s
fix: update build dependencies and improve documentation
- Fix gettext-parser 9 compatibility and update Babel parser
- Apply targeted dependency security fixes and align Node.js requirements
- Add regression tests and document remaining dependency risks
- Review bundled player dependencies and advisory reachability
- Reformat English and Chinese READMEs and simplify wording
- Remove plugin version descriptions from README files

PR #39
2026-10-14 17:43:24 +08:00

50 lines
2.6 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import gettext from 'gettext-parser';
const po = gettext.po.parse(fs.readFileSync('languages/wp-asciiplayer-zh_CN.po'));
const mo = gettext.mo.parse(fs.readFileSync('languages/wp-asciiplayer-zh_CN.mo'));
const pot = gettext.po.parse(fs.readFileSync('languages/wp-asciiplayer.pot'));
const editor = JSON.parse(fs.readFileSync('languages/wp-asciiplayer-zh_CN-lamgc-asciiplayer-editor.json')).locale_data.messages;
const view = JSON.parse(fs.readFileSync('languages/wp-asciiplayer-zh_CN-lamgc-asciiplayer-view.json')).locale_data.messages;
test('all extracted strings and gettext contexts round-trip through MO and both script catalogs', () => {
let count = 0;
for (const [context, entries] of Object.entries(pot.translations)) {
for (const entry of Object.values(entries)) {
if (!entry.msgid) continue;
count++;
const translated = po.translations[context][entry.msgid].msgstr;
assert.ok(translated[0]);
assert.deepEqual(mo.translations[context][entry.msgid].msgstr, translated);
const key = context ? `${context}\u0004${entry.msgid}` : entry.msgid;
assert.deepEqual(editor[key], translated);
assert.deepEqual(view[key], translated);
}
}
assert.ok(count >= 75);
});
test('catalogs use Chinese plural rules, exact locale, and standard WordPress textdomain', () => {
assert.equal(po.headers.Language, 'zh_CN');
assert.equal(mo.headers.Language, 'zh_CN');
assert.equal(po.headers['Plural-Forms'], 'nplurals=1; plural=0;');
assert.equal(mo.headers['Plural-Forms'], 'nplurals=1; plural=0;');
assert.equal(pot.headers['Project-Id-Version'], `wp-asciiplayer ${JSON.parse(fs.readFileSync('package.json')).version}`);
assert.equal(pot.headers['Content-Type'], 'text/plain; charset=utf-8');
assert.equal(editor[''].lang, 'zh_CN');
assert.equal(editor[''].domain, 'wp-asciiplayer');
assert.equal(editor['']['plural-forms'], 'nplurals=1; plural=0;');
assert.equal(editor['block title\u0004Asciicast Player'][0], 'Asciicast 播放器');
assert.equal(editor['Recording URL'][0], '录制文件 URL');
});
test('Unicode, punctuation, percentages and literal author content are preserved', () => {
assert.equal(editor['Add a caption…'][0], '添加说明文字…');
assert.match(editor['Use a CSS length, such as 480px or 65%. The player stays within its available space.'][0], /480px.*65%/);
assert.equal(editor['Author caption / 作者说明'], undefined);
const serialized = JSON.stringify(editor);
assert.deepEqual(JSON.parse(serialized), editor);
});