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

@openworkflowspec/i18n

v1.1.0

Published

Open workflow internationalization component

Downloads

250

Readme

@openworkflowspec/i18n

A lightweight internationalization (i18n) package for React applications, providing simple translation support with automatic locale detection.

Overview

This package provides a minimal i18n solution built on React Context, designed for use in the Open Workflow Diagram Editor and other React applications.

Features

  • React Context-based: Simple provider/hook pattern
  • Automatic locale detection: Uses browser language preferences
  • Type-safe: Built with TypeScript
  • Lightweight: No heavy dependencies
  • Fallback support: Returns keys when translations are missing

Installation

pnpm add @openworkflowspec/i18n

API Reference

Exports

  • I18nProvider - React context provider for translations
  • useI18n() - Hook to access translation function and current locale
  • createI18n() - Core translation logic (typically used internally)
  • detectLocale() - Automatically detect user's preferred language

Types

type Dictionary = Record<string, string>;
type Dictionaries = Record<string, Dictionary>;

Usage

1. Define your translation dictionaries

Create a file with your translations for each supported language:

// i18n/locales.ts
export const dictionaries = {
  en: {
    save: "Save",
    cancel: "Cancel",
    delete: "Delete",
  },
  fr: {
    save: "Enregistrer",
    cancel: "Annuler",
    delete: "Supprimer",
  },
};

Important: Translation keys must be consistent across all languages.

2. Detect or specify locale

Choose the user's locale either manually or through automatic detection:

import { detectLocale } from "@openworkflowspec/i18n";
import { dictionaries } from "./i18n/locales";

const supportedLocales = Object.keys(dictionaries) as Array<keyof typeof dictionaries>;

// Auto-detect with fallback to "en"
const locale = detectLocale(supportedLocales);

// Or specify manually
const locale = "fr";

// Or combine both approaches
const locale = props.locale ?? detectLocale(supportedLocales, "en");

detectLocale() behavior:

  • Uses navigator.languages and navigator.language to detect user preferences
  • Normalizes locales to their base language code (e.g., "en-US""en")
  • Returns the fallback parameter (default: "en") if no match found
  • Returns fallback in non-browser environments (SSR-safe)

3. Wrap your app with I18nProvider

import { I18nProvider } from "@openworkflowspec/i18n";
import { dictionaries } from "./i18n/locales";

function App() {
  const locale = detectLocale(Object.keys(dictionaries));

  return (
    <I18nProvider locale={locale} dictionaries={dictionaries}>
      <YourAppContent />
    </I18nProvider>
  );
}

4. Use translations with useI18n()

Inside any component within the provider:

import { useI18n } from "@openworkflowspec/i18n";

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

  return (
    <div>
      <p>Current locale: {locale}</p>
      <button>{t("save")}</button>
      <button>{t("cancel")}</button>
    </div>
  );
}

Translation fallback: If a key is missing, t() returns the key itself:

t("unknown_key"); // Returns: "unknown_key"

Error handling: useI18n() must be used inside I18nProvider or it will throw an error.

Architecture

src/
├── index.ts                    # Public exports
├── core/
│   └── createI18n.ts          # Core translation logic
├── react/
│   └── I18nProvider.tsx       # React Context provider and hook
└── utils/
    └── detectLocale.ts        # Browser locale detection

Development

Build

# Development build
pnpm build:dev

# Production build (includes tests)
pnpm build:prod

Test

pnpm test

Tests are located in the tests/ directory and use Vitest.

TypeScript

This package is written in TypeScript and includes type definitions. The build outputs:

  • dist/index.js - ESM JavaScript
  • dist/index.d.ts - TypeScript declarations

License

Apache-2.0

Repository

Part of the Open Workflow Editor monorepo.