build: package browser extension locale catalogs

This commit is contained in:
2026-07-11 22:22:20 +08:00
parent cae140a348
commit 604bb459c8
5 changed files with 46 additions and 5 deletions
+11 -1
View File
@@ -38,6 +38,13 @@ function copyIcons(destRoot) {
}
}
function copyLocalization(destRoot) {
copy(path.join(shared, 'i18n.js'), path.join(destRoot, 'i18n.js'));
for (const locale of ['en', 'ru']) {
copy(path.join(shared, 'locales', `${locale}.json`), path.join(destRoot, 'locales', `${locale}.json`));
}
}
rm(dist);
const chromiumDist = path.join(dist, 'chromium');
@@ -47,18 +54,21 @@ concat([
path.join(shared, 'protocol.js'),
path.join(shared, 'api.js'),
path.join(shared, 'queue.js'),
path.join(shared, 'i18n.js'),
path.join(shared, 'background.js'),
], path.join(chromiumDist, 'background.js'));
copyPopup(chromiumDist);
copyIcons(chromiumDist);
copyLocalization(chromiumDist);
const firefoxDist = path.join(dist, 'firefox');
mkdir(firefoxDist);
copy(path.join(root, 'firefox', 'manifest.json'), path.join(firefoxDist, 'manifest.json'));
for (const name of ['protocol.js', 'api.js', 'queue.js', 'background.js']) {
for (const name of ['protocol.js', 'api.js', 'queue.js', 'i18n.js', 'background.js']) {
copy(path.join(shared, name), path.join(firefoxDist, name));
}
copyPopup(firefoxDist);
copyIcons(firefoxDist);
copyLocalization(firefoxDist);
console.log('built dist/chromium and dist/firefox');
+2 -2
View File
@@ -34,9 +34,9 @@ const browser = {
},
},
contextMenus: {
removeAll(callback) {
removeAll() {
menuTitles = [];
if (callback) callback();
return Promise.resolve();
},
create(item) {
menuTitles.push(item.title);
+12
View File
@@ -33,6 +33,18 @@ assert.strictEqual(tEn('error.value', { error: 'offline' }), 'Error: offline');
assert.strictEqual(tRu('missing', null, 'Fallback'), 'Fallback');
assert.strictEqual(tRu('missing.key'), 'missing.key');
const dist = path.join(root, 'dist');
if (fs.existsSync(dist)) {
for (const target of ['chromium', 'firefox']) {
for (const relativePath of ['i18n.js', 'locales/en.json', 'locales/ru.json']) {
assert.ok(
fs.existsSync(path.join(dist, target, relativePath)),
`${target} build is missing ${relativePath}`,
);
}
}
}
i18n.loadCatalogs((locale) => Promise.resolve(locale === 'ru' ? ru : en))
.then((catalogs) => {
assert.strictEqual(catalogs.en, en);