@sphinxjs/core
v0.0.1
Published
The core engine, store, types, and loader for Sphinx.
Readme
@sphinxjs/core
The core engine, store, types, and loader for Sphinx.
Install
pnpm add @sphinxjs/coreAPI
Sphinx class
The translation engine. Holds locale data and resolves translated strings.
import { Sphinx } from "@sphinxjs/core";
const sphinx = new Sphinx({
locales: ["en", "fr"],
defaultLocale: "en",
locale: "fr",
translations: {
fr: {
"": { headers: {}, translations: { "": { Hello: { msgid: "Hello", msgstr: ["Bonjour"] } } } },
},
},
});
sphinx.getMessageData({ msgid: "Hello", context: null, domain: null, locale: null });initSphinx(props?) / getSphinx() / resetSphinx()
Manage the global singleton instance backed by a nanostores atom.
import { initSphinx, getSphinx } from "@sphinxjs/core";
initSphinx({ locales: ["en", "fr"], locale: "en" });
const { sphinx } = getSphinx();getMessagePlural({ message, count })
Evaluate a PO plural-forms expression for a given count.
Loading translations
Use @sphinxjs/loader to load .po files from Vite/Astro import globs into the DomainTranslations shape expected by initSphinx.
Types
All shared types (Label, TranslationInformation, GettextUtilities, SphinxContextProps, SphinxGetter, NormaliseLabelOptions, …) are exported from this package.
