27 lines
1.4 KiB
TypeScript
27 lines
1.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { readdirSync } from 'node:fs';
|
|
import test from 'node:test';
|
|
import en from '../locales/en.json' with { type: 'json' };
|
|
import { pluginCatalogNamespace } from '../src/inject/i18n.ts';
|
|
|
|
const bundled = readdirSync(new URL('../src-tauri/bundled-plugins/', import.meta.url)).filter(file => file.endsWith('.plugin.js'));
|
|
const keys = Object.keys(en.messages as Record<string, string>);
|
|
|
|
test('bundled plugins, installed as bt-<name>.plugin.js, read their plugin.<name>.* strings', () => {
|
|
// Found live: every bundled plugin stayed English in Turkish/Arabic, because the installed
|
|
// file bt-copy-as-markdown.plugin.js looked for plugin.bt-copy-as-markdown.* keys.
|
|
let translated = 0;
|
|
for (const file of bundled) {
|
|
const name = file.replace(/\.plugin\.js$/, '');
|
|
if (!keys.some(key => key.startsWith(`plugin.${name}.`))) continue;
|
|
translated += 1;
|
|
assert.equal(pluginCatalogNamespace(`bt-${file}`), name, file);
|
|
}
|
|
assert.ok(translated >= 10, `${translated} bundled plugins have catalog strings`);
|
|
});
|
|
|
|
test('other plugin files keep their own namespace', () => {
|
|
assert.equal(pluginCatalogNamespace('my-tool.plugin.js'), 'my-tool');
|
|
assert.equal(pluginCatalogNamespace('bt-not-bundled.plugin.js'), 'bt-not-bundled');
|
|
assert.equal(pluginCatalogNamespace('example-hide-trends.plugin.js'), 'example-hide-trends');
|
|
});
|