@sphinxjs/gettext
v0.0.1
Published
Gettext-compatible translation functions for Sphinx. Provides both bound (global store) and unbound (injectable) variants.
Readme
@sphinxjs/gettext
Gettext-compatible translation functions for Sphinx. Provides both bound (global store) and unbound (injectable) variants.
Install
pnpm add @sphinxjs/gettextAPI
Bound functions (use the global store)
Import and call directly, no setup beyond initSphinx:
import {
gettext,
ngettext,
pgettext,
npgettext,
dgettext,
dngettext,
dpgettext,
dnpgettext,
textdomain,
_,
} from "@sphinxjs/gettext";
const msg = gettext("Hello");
const plural = ngettext("One item", "%d items", count);
const ctx = pgettext("menu", "File");Unbound functions
All bound functions have an unbound* counterpart that takes a SphinxGetter as the first argument. Used for scoped instances (e.g. domain-bound hooks):
import { unboundGettext, unboundGettextUtilities } from "@sphinxjs/gettext";
import { getSphinx } from "@sphinxjs/core";
const t = unboundGettext.bind(null, getSphinx);unboundGettextUtilities(getter)
Returns a GettextUtilities object with all functions pre-bound to the given getter. Used internally by @sphinxjs/react.
import { unboundGettextUtilities } from "@sphinxjs/gettext";
const utils = unboundGettextUtilities(getSphinx);
utils.gettext("Hello");