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

@zachhandley/ez-i18n-react

v0.4.0

Published

React integration for @zachhandley/ez-i18n - Cookie-based i18n with reactive language switching

Readme

@zachhandley/ez-i18n-react

React integration for @zachhandley/ez-i18n - Cookie-based i18n with reactive language switching.

Installation

pnpm add @zachhandley/ez-i18n @zachhandley/ez-i18n-react @nanostores/react

Usage

import { useI18n } from '@zachhandley/ez-i18n-react';

function MyComponent() {
  const { t, locale, setLocale } = useI18n();

  return (
    <div>
      <h1>{t('common.welcome')}</h1>
      <p>{t('greeting', { name: 'World' })}</p>
      <p>{t('[i18n:greeting|name=World]')}</p>
      <button onClick={() => setLocale('es')}>Español</button>
      <p>Current locale: {locale}</p>
    </div>
  );
}

Embedded i18n Strings

t() accepts embedded i18n strings, which are formatted in the active locale:

<p>{t('[i18n:greeting|name=World]')}</p>
<p>{t('Hello [i18n:greeting|name=World]!')}</p>

API

useI18n()

Returns an object with:

  • t(key: string, params?: Record<string, string | number>) - Translation function (reactive - component re-renders when translations change)
  • locale: string - Current locale
  • setLocale(locale: string) - Function to change locale

useTranslation(key, params?)

A convenience hook that subscribes to a single translation key and returns the translated string. The component automatically re-renders when the locale or translation changes.

import { useTranslation } from '@zachhandley/ez-i18n-react';

function PageTitle() {
  // Subscribes to this specific translation key
  const title = useTranslation('page.title');
  const greeting = useTranslation('welcome.message', { name: 'Alice' });

  return (
    <div>
      <h1>{title}</h1>
      <p>{greeting}</p>
    </div>
  );
}

Note on Reactivity:

In React, the t() function from useI18n() is already reactive - your component will automatically re-render when the locale or translations change. The useTranslation() hook is provided as a convenience for subscribing to individual translation keys, but both approaches are reactive.

// Both of these are reactive and will update on locale change:

// Approach 1: Using t() from useI18n
function Component1() {
  const { t } = useI18n();
  return <h1>{t('welcome.title')}</h1>; // Re-renders on locale change
}

// Approach 2: Using useTranslation hook
function Component2() {
  const title = useTranslation('welcome.title');
  return <h1>{title}</h1>; // Also re-renders on locale change
}

Accessing Config & Locale Utilities

Access configuration and locale metadata from the core package:

import { useI18n } from '@zachhandley/ez-i18n-react';
import { locales, localeNames, localeDirections } from 'ez-i18n:config';
import { getLocaleInfo } from '@zachhandley/ez-i18n';

function LanguageSwitcher() {
  const { locale, setLocale } = useI18n();

  return (
    <select value={locale} onChange={(e) => setLocale(e.target.value)}>
      {locales.map((loc) => (
        <option key={loc} value={loc}>
          {localeNames[loc]} {/* Native name: "Español" */}
        </option>
      ))}
    </select>
  );
}

// Or get full locale info
const info = getLocaleInfo('ar');
// { name: 'العربية', englishName: 'Arabic', bcp47: 'ar-SA', dir: 'rtl' }

How It Works

This package imports the shared store instance from @zachhandley/ez-i18n/runtime as a peer dependency. This ensures that all components in your application share the same translation state, enabling reactive updates across your entire React app when the locale changes.

License

MIT