waybetter-for-x/scripts/i18n-extract.mjs
2026-09-30 23:01:13 +00:00

25 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
// Lists the message keys the app's code looks up and compares them with the English source
// catalog (docs/TRANSLATING.md). A developer runs it after adding UI text. This is
// `waybetter i18n extract` (waybetter/packages/waybetter/cli/i18n.mjs) with this repository's
// waybetter.i18n.json.
//
// node scripts/i18n-extract.mjs keys used in code but missing from en.json (exit 1),
// then keys en.json has that no literal lookup names
// node scripts/i18n-extract.mjs --missing only the missing keys
//
// Keys built at runtime (`features.${id}.label`) are invisible here, so "no literal lookup" is a
// hint, never a reason to delete: check with a search first. `plugin.*` keys belong to bundled
// plugins (their inline English is compared by the check), `native.app.*` to the generated native
// files.
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { i18nCommand } from '../waybetter/packages/waybetter/cli/i18n.mjs';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
try {
process.exit(await i18nCommand(['extract', ...process.argv.slice(2)], { cwd: root }));
} catch (error) {
console.error(`i18n-extract: ${error instanceof Error ? error.message : error}`);
process.exit(1);
}