@sphinxjs/loader
v0.0.1
Published
> **Deprecated.** Use `sphinx sync` to compile your PO files into a static > translations file and import it directly. `@sphinxjs/loader` continues to > work but will not receive new features. See the [CLI reference][cli] for the > recommended workflow. >
Readme
Deprecated. Use
sphinx syncto compile your PO files into a static translations file and import it directly.@sphinxjs/loadercontinues to work but will not receive new features. See the CLI reference for the recommended workflow.
@sphinxjs/loader
Loads .po translation files from a Vite/Astro import glob into the DomainTranslations map expected by initSphinx.
Install
pnpm add @sphinxjs/loaderAPI
getGlobTranslations(glob, domain?)
Accepts a Vite glob import record of raw .po file strings, parses each one, and returns a DomainTranslations object keyed by locale.
import { getGlobTranslations } from "@sphinxjs/loader";
import { initSphinx } from "@sphinxjs/core";
const translations = await getGlobTranslations(
import.meta.glob("./locales/*.po", { query: "?raw", import: "default" }),
);
initSphinx({ locales: ["en", "fr"], locale: "en", translations });The locale name is inferred from the filename, ./locales/fr.po → "fr".
The optional domain argument (default "") assigns all loaded translations to a named gettext domain:
const adminTranslations = await getGlobTranslations(
import.meta.glob("./locales/admin/*.po", { query: "?raw", import: "default" }),
"admin",
);