npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sphinxjs/label

v0.0.1

Published

Translates and normalises `Label` values, the bridge between your data model and displayed text.

Readme

@sphinxjs/label

Translates and normalises Label values, the bridge between your data model and displayed text.

Why this package exists

Many UI components need to display a name for something: a collection title, a field label, an action button. That name might be:

  • A hardcoded string, "Employees"
  • A translated string, looked up from a .po catalog at render time
  • Derived from a key, "paymentRequest""Payment Requests"

Instead of handling each case at every call site, you declare a Label type on your props and let normaliseLabel resolve it to a plain string:

type Label = string | TranslationInformation;

interface CollectionConfig {
  label: Label;
  labelPlural?: Label;
}

Components and configs never deal with translation directly, they just hold a Label. Translation happens once, at the boundary where text meets the UI.

Install

pnpm add @sphinxjs/label

Usage

translateLabel(label, options?)

Resolves a Label to a translated string using the global Sphinx store. Plain strings pass through unchanged. TranslationInformation objects are looked up in the active locale's catalog.

import { translateLabel } from "@sphinxjs/label";

// Plain string, returned as-is
translateLabel("Employees");
// → "Employees"

// TranslationInformation, looked up in catalog
translateLabel({ msgid: "Employee" });
// → "Mitarbeiter"  (with German locale active)

// With plural form
translateLabel({ msgid: "Employee", plural: "Employees" }, { count: 3 });
// → "Mitarbeiter"  (singular) or "Mitarbeiter" (plural, translated)

normaliseLabel(label?, options?)

Like translateLabel but handles three additional cases:

  • undefined label with a fallbackKey, converts a camelCase or snake_case key to a human-readable string
  • singular: true / plural: true, coerces the result through pluralize regardless of count
  • undefined with no fallback, returns undefined
import { normaliseLabel } from "@sphinxjs/label";

// Translate a TranslationInformation and force plural form
normaliseLabel({ msgid: "Invoice" }, { plural: true });
// → "Invoices"  (translated + pluralised)

// Humanise a config key when no label is defined
normaliseLabel(undefined, { fallbackKey: "paymentRequest", plural: true });
// → "Payment Requests"

// Plain string, forced to singular
normaliseLabel("Employees", { singular: true });
// → "Employee"

This is particularly useful in generic components that receive a config object, they can display a reasonable label even when the author didn't explicitly set one.

Options

| Option | Type | Description | | ------------- | --------- | -------------------------------------------------------------- | | count | number | Selects plural form during catalog lookup (default 1) | | plural | boolean | Force plural form via pluralize after translation | | singular | boolean | Force singular form via pluralize after translation | | fallbackKey | string | camelCase/snake_case key to humanise when label is undefined |

TranslationInformation builders

These functions construct TranslationInformation objects that can be stored in config and resolved later by translateLabel / normaliseLabel. They mirror the standard gettext API but return objects instead of strings.

import { gettext, ngettext, pgettext, dgettext } from "@sphinxjs/label";

const config = {
  label: gettext("Invoice"),
  labelPlural: ngettext("Invoice", "Invoices"),
  // With context
  action: pgettext("button", "Save"),
  // From a specific domain
  status: dgettext("billing", "Paid"),
};

Advanced: unbound variants

unboundTranslateLabel and unboundNormaliseLabel accept a SphinxGetter as their first argument. Use these when you need to translate against a specific Sphinx instance rather than the global store, for example in tests, server-side rendering with per-request instances, or domain-scoped hooks.

import { unboundTranslateLabel } from "@sphinxjs/label";

unboundTranslateLabel(mySphinxGetter, { msgid: "Invoice" });