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

@rgglez/react-i18n-gettext

v0.1.1

Published

Translations (i18n) for React using gettext: provider and hook with live language switching.

Readme

react-i18n-gettext

License

gettext translations for React: a provider and a hook with live language switching. Built on @rgglez/i18n-gettext, the same core as svelte-i18n-gettext and astro-i18n-gettext, so the same .json catalogs work everywhere.

Install

npm install @rgglez/react-i18n-gettext

Requires React 18 or later.

Usage

Wrap the tree once:

import { GettextProvider } from "@rgglez/react-i18n-gettext";
import de from "./i18n/de-DE/messages.json";
import es from "./i18n/es-MX/messages.json";

const catalogs = { "de-DE": de, "es-MX": es };

export function App() {
  return (
    <GettextProvider lang="es-MX" catalogs={catalogs}>
      <Page />
    </GettextProvider>
  );
}

Translate anywhere below it:

import { sprintf, useGettext } from "@rgglez/react-i18n-gettext";

function Page() {
  const { _, _n, lang, setLang } = useGettext();
  return (
    <>
      <p>{_("This is an example of a static string")}</p>
      <p>{sprintf(_("Hello %s, you won $%s"), name, prize)}</p>
      <p>{sprintf(_n("One file deleted", "%d files deleted", n), n)}</p>
      <button onClick={() => setLang("de-DE")}>Deutsch</button>
    </>
  );
}

setLang re-renders every consumer with the new language. A new lang prop on the provider (for example after a route change) replaces any language set with setLang. Define catalogs outside the component or memoize it: a new object on every render rebuilds the translator.

The language is React state, not a module global, so the provider is safe for server rendering (Next.js, Remix, React Router) with concurrent requests.

API

| Export | Description | | :----- | :---------- | | <GettextProvider lang catalogs> | Provides translations to its subtree | | useGettext() | { _, _n, lang, setLang, hasTranslations }; throws outside a provider | | sprintf, vsprintf | Re-exported from the core |

_(msgid, msgctxt = "app")
_n(msgid, msgidPlural = "", count = 0, msgctxt = "app")

Missing translations return the msgid. Locales resolve exactly first, then by primary language (es ↔ es-MX).

Catalogs

Catalogs are gettext .po files converted to gettext-parser JSON with gettext-po2json and the app context. Extract strings with xgettext (gettext 0.23+ for -L TSX):

xgettext -o messages.pot -L TSX --from-code=utf-8 --no-wrap \
  --keyword=_ --keyword=_n:1,2 src/**/*.tsx
perl po2json.pl --po es-MX.po --json es-MX/messages.json --context app

Development

bun install
bun test src
bun run build

License

Copyright (c) 2026 Rodolfo González González.

Licensed under the Apache-2.0 license. Read the LICENSE file.