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

donkey-i18n

v1.0.2

Published

A tiny and thoroughly type-safe internationalization helper for TypeScript, with support for React.

Readme

Donkey i18n 🐴🌐

A tiny and thoroughly type-safe internationalization helper for TypeScript and includes a React-specific hook. It's designed to be a quick way to add i18n support to your prototypes or small projects, and is meant to be easily replaced if you outgrow it.

Features

  • Type-safe keys: Get auto-complete and catch typos in your code
  • Nested paths: Support for deep objects like settings.title
  • Runtime safety: Throws an error if you request a missing key
  • React hook: useTranslator gives you a memoized t() function to translate

Installation

npm install donkey-i18n

Usage

1. Define your dictionaries

// define your base language's dictionary
const en = {
    settings: {
        title: "Welcome to Settings",
        description: "This is the settings page.",
    },
    login: "Login",
};

// typing not needed but highly recommended so that both languages have the same structure
type LangDict = typeof en;

const fr: LangDict = {
    settings: {
        title: "Bienvenue dans les paramètres",
        description: "Ceci est la page des paramètres.",
    },
    login: "Connexion",
};

const dict = { en, fr };

2. Detect browser locale (optional)

import { getBrowserLocale } from "donkey-i18n";

const locale = getBrowserLocale({
    dictionary: dict,
    fallbackLocale: "en",
});

// If `navigator.languages` includes "fr", you get "fr", otherwise "en".

3. Create a translator

import { createTranslationFunction } from "donkey-i18n";

const { t } = createTranslationFunction({
    dictionary: dict,
    locale: "en",
});

// Or with React
import { useTranslator } from "donkey-i18n";

function MyComponent() {
    const { t } = useTranslator({ dictionary: dict, "en" });
}

console.log(t("login")); // → "Login"
console.log(t("settings.title")); // → "Welcome to Settings"

API Reference

| Function | Description | Parameters | Returns | | ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | | getBrowserLocale({ dictionary, fallbackLocale }) | Auto-detects the best locale based on the browser. | - dictionary (object): your whole locale dictionary- fallbackLocale (string): used if no match in navigator.languages | The best matching locale key, or the fallback. | | createTranslationFunction({ dictionary, locale }) | Creates a translation function for a specific locale. | - dictionary (object): your full locale dictionary- locale (string): the current language key (e.g., "en", "fr") | { t }, a type-safe wrapper around getTranslationFromDict for the given language. Example: t("settings.title") | | useTranslator({ dictionary, locale }) | React hook version of createTranslationFunction, memoized for performance. | - dictionary (object): your full locale dictionary- locale (string): the current language key | { t }, a type-safe wrapper around getTranslationFromDict for the given language. Example: t("settings.title") | | getTranslationFromDict(dict, path) | Lower-level helper for manually fetching translations by path. Mostly for internal use, but may be useful. | - dict (object): translations for a specific locale (e.g., dict.en)- path (string): like "login" or "settings.description" | The translated string. Throws an error if the path doesn't exist |