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

@pomle/react-node-i18n

v0.0.0-5

Published

React Node based i18n library.

Readme

React Node Internationalization

An internationalization library based on React components.

Usage

  1. Create setup file to create the i18n context. You can use any list of strings as keys. We recommend using some kind of ISO reference.
import { createInternationalizationContext } from "@pomle/react-node-i18n";

export enum Locale {
  enGB = "en_GB",
  svSE = "sv_SE",
}

const {
  InternationalizationProvider,
  localize,
  useInternationalization,
  useLocale,
} = createInternationalizationContext([
  Locale.enGB,
  Locale.svSE,
]);

export {
  InternationalizationProvider,
  localize,
  useInternationalization,
  useLocale,
};
  1. Import InternationalizationProvider from setup file and mount in your app. Implement state here if you need the app to be able to set the language. The onChange function will be called when locale is set.
import { RestOfTheApp } from "./App.tsx";
import { InternationalizationProvider, Locale } from "i18n/localization";

function Internationalization({children}) {
  const [locale, setLocale] = useState(Locale.enGB);

  return <InternationalizationProvider locale={locale} onChange={setLocale}>
    {children}
  </InternationalizationProvider>
}

export function App() {
  return (
    <Internationalization>
      <RestOfTheApp/>
    </Internationalization>
  );
}
  1. Import and use localize function from setup file and call to create translation components. We recommend one sibling file per component called trans.tsx that export all translatables as a single object.
import { localize } from "lib/i18n/localization";

const Title = localize({
  en_GB: <>My Age</>,
  sv_SE: <>Min ålder</>,
});

export const Trans = { Title };
  1. Import translations and render.
import { Trans } from "./trans";

export function AgeComponent({age}: {age: number}) {
  return <div>
    <Trans.Title> {age}
  </div>
}
  1. The useInternationalization hook will provide access to the current, and the set function you provide.
import { useInternationalization } from "i18n/localization";

export function LocaleSelector() {
  const {locale, setLocale} = useInternationalization();

  return <>
    {[Locale.enGB, Locale.svSE].map(locale => {
      <button onClick={() => setLocale(locale)}>
        {locale}
      </button>
    })}
  </>;
}

Reference

createInternationalizationContext

Core function that creates all utilities needed.

InternationalizationProvider

Context provider component that provides functionality for useInternationalization and useLocale. A basic implementation of a React Context.

localize

Factory function returned by createInternationalizationContext that creates React components with localization support.

This is the function you will use the most.

It requires a specification for each language to be set, and then ensures that the correct output emitted based on the set locale.

import { localize } from "lib/i18n/localization"; // Your setup file

const Age = localize<{age: number}>({
  en_GB: ({age}) => <>My age: {age}</>,
  sv_SE: ({age}) => <>Min ålder: {age}</>,
});

function MyComponent() {
  return <div>
    <h1><Age age={37} /></h1>
  </div
}

It provides three ways to define translations.

  1. Strings when you want simplicity.
const Age = localize({
  en_GB: "Age",
  sv_SE: "Ålder",
});
  1. React Fragments for when you need to output HTML.
const Age = localize({
  en_GB: <>My <b>Age</b></>,
  sv_SE: <>Min <b>Ålder</b></>,
});
  1. React component for when you need arguments and templating.
const Age = localize<{age: number}>({
  en_GB: ({age}) => <>My Age is <b>{age}</b></>,
  sv_SE: ({age}) => <>Min ålder är <b>{age}</b></>,
});

Emit translation by mounting component.

const Age = localize({
  "en-US": "Age",
  "sv-SE": "Ålder",
});

function Component() {
  return <div>
    <Age/>
  </div>
}

When translation defined without HTML you can call it as a function to emit it's string value.

const Age = localize({
  "en-US": "Age",
  "sv-SE": "Ålder",
});

function Component() {
  return <input placeholder={Age()} />;
}

useInternationalization

Hook that provides access to currently selected locale and a setter function to set locale. Calling setLocale will trigger the onChange callback given to InternationalizationProvider.

function Component() {
  const {locale, setLocale} = useInternationalization();

  // Read of set locale

  return null;
}

useLocale

Convenience hook that returns only the currently selected locale.

Pluralization

This library have no opinions on pluralization or other deviations. However, below are some examples for inspiration.

const Age = localize<{age: number}>({
  "en-US": ({age}) => {
    if (age === 1) {
      return <>1 year old</>;
    }

    return <>{age} years old</>;
  },
  "sv-SE": ({age}) => <>{age} år gammal</>,
});