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

@knaw-huc/sd-common-i18n

v0.0.1

Published

A lightweight React internationalization (i18n) library for sharing translation capabilities across (KNAW HUC) packages. It works with your existing i18n solution (react-intl, i18next, etc.) or standalone with its own built-in translation management.

Readme

@knaw-huc/common-i18n

A lightweight React internationalization (i18n) library for sharing translation capabilities across (KNAW HUC) packages. It works with your existing i18n solution (react-intl, i18next, etc.) or standalone with its own built-in translation management.

Installation

npm install @knaw-huc/common-i18n

React 19 is a peer dependency.

Quick Start

Wrap your app with I18nProvider and use the useTranslate hook in components:

import { I18nProvider, useTranslate } from '@knaw-huc/common-i18n';

const translations = {
  'greeting': 'Hello, {{name}}!',
  'search.button': 'Search',
};

function App() {
  return (
    <I18nProvider defaultTranslations={translations} locale="en">
      <MyComponent />
    </I18nProvider>
  );
}

function MyComponent() {
  const { t } = useTranslate();
  return <button>{t('search.button')}</button>; // → "Search"
}

API

I18nProvider

The context provider that supplies translation and locale to the component tree.

<I18nProvider
  defaultTranslations={{ 'key': 'Default text' }}
  translations={{ 'key': 'Override text' }}
  locale="en-US"
>
  {children}
</I18nProvider>

| Prop | Type | Description | |---|---|---| | defaultTranslations | Record<string, string> | Baseline translation strings | | translations | Partial<Record<string, string>> | Partial overrides applied on top of defaultTranslations | | translate | TranslateFn | Custom translate function — takes precedence over all translations | | locale | string \| Intl.Locale | Locale identifier, defaults to 'en' | | children | ReactNode | Component children |

Translation priority (highest to lowest):

  1. Custom translate function
  2. Merged defaultTranslations + translations overrides
  3. Fallback to the key itself

useTranslate

Returns a t function for translating keys.

const { t } = useTranslate();

t('greeting')                       // → "Hello, {{name}}!"
t('greeting', { name: 'Alice' })    // → "Hello, Alice!"
t('unknown.key')                    // → "unknown.key" (fallback)

Supports {{key}} placeholder interpolation. If used outside a provider, keys are returned as-is.

useLocale

Returns the current locale as an Intl.Locale object.

const locale = useLocale();
locale.language  // → "en"
locale.region    // → "US"

Defaults to 'en' if used outside a provider.

createTranslateFn

Creates a TranslateFn from a translations map. Useful for constructing translate functions manually.

import { createTranslateFn } from '@knaw-huc/common-i18n';

const t = createTranslateFn({ 'hello': 'Hello, {{name}}!' });
t('hello', { name: 'World' }); // → "Hello, World!"
t('missing');                  // → "missing"

Using with an External i18n Library

Pass a custom translate function to delegate to your preferred library:

import { useIntl } from 'react-intl';

function I18nBridge({ children }) {
  const intl = useIntl();
  return (
    <I18nProvider translate={(key, options) => intl.formatMessage({ id: key }, options)}>
      {children}
    </I18nProvider>
  );
}

Types

type TranslateFn = (key: string, options?: Record<string, unknown>) => string;
type TranslationKey = string;

Development

npm run build          # Build the library
npm run prepublishOnly # Build before publishing (runs automatically)

Output is an ES module bundle in dist/. TypeScript declarations are generated for all exports.