@sphinxjs/extractor
v0.0.1
Published
POT string extraction engine. Scans TypeScript, JavaScript, JSX, TSX, HTML, and (optionally) Astro source files for gettext calls and produces a `.pot` template file.
Readme
@sphinxjs/extractor
POT string extraction engine. Scans TypeScript, JavaScript, JSX, TSX, HTML, and (optionally) Astro source files for gettext calls and produces a .pot template file.
Install
pnpm add -D @sphinxjs/extractorFor Astro support also install the optional parser:
pnpm add -D @sphinxjs/extractor-astroAPI
extract(options)
import { extract } from "@sphinxjs/extractor";
const { stats, potString } = await extract({
base: "./src", // source root (default: "./src")
output: "./po", // write messages.pot here (omit to skip writing)
printStats: true, // print extraction stats to stdout
projectName: "my-app",
projectVersion: "1.0.0",
});Extracted call patterns
| Call | Arguments extracted |
| ----------------------------------------- | ---------------------------- |
| gettext(msg) / _(msg) | msgid |
| ngettext(msg, plural, n) | msgid, msgid_plural |
| pgettext(ctx, msg) | context, msgid |
| npgettext(ctx, msg, plural, n) | context, msgid, msgid_plural |
| dgettext(domain, msg) | msgid |
| dpgettext(domain, ctx, msg) | context, msgid |
| dngettext(domain, msg, plural, n) | msgid, msgid_plural |
| dnpgettext(domain, ctx, msg, plural, n) | context, msgid, msgid_plural |
| <translate>…</translate> (HTML) | element content |
Astro files are handled by @sphinxjs/extractor-astro when installed, the extractor dynamically imports it and falls back gracefully if it is absent.
