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

flat-i18n

v0.1.3

Published

Flat JSON based i18n. Zero magic.

Readme

flat-i18n

Flat JSON based i18n. Zero magic.

flat-i18n is a minimal internationalization utility for JavaScript and React applications. It is designed for developers who want full control, predictable behavior, and no framework lock-in.

  • No routing coupling
  • No async loaders
  • No hidden state

Just JSON → Getter → (Optional) React Provider.


Table of Contents


Why flat-i18n?

Most i18n libraries are over-engineered.

flat-i18n exists because sometimes you just want:

  • one JSON file
  • flat keys
  • O(1) lookups
  • server + client support
  • zero dependencies
  • zero magic

If that resonates, this library is for you.


Features

  • ✅ Flat JSON structure
  • ✅ Framework-agnostic core
  • ✅ Optional React provider
  • ✅ Works in Node, Edge, and Client environments
  • ✅ SSR-safe
  • ✅ Tree-shakable
  • ✅ Zero runtime dependencies
  • ✅ TypeScript-first

Installation

npm install flat-i18n

JSON format

flat-i18n expects one single JSON file with language keys at the top level.

{
  "en": {
    "app.name": "PinPocket",
    "nav.home": "Home",
    "seo.title": "Save, Organize, Collaborate"
  },
  "es": {
    "app.name": "PinPocket",
    "nav.home": "Inicio",
    "seo.title": "Guardar, Organizar, Colaborar"
  }
}

Design rules

  • Keys are flat (no nesting)
  • Values are strings only
  • No runtime mutation
  • No dynamic loading

Setup (required)

Before using flat-i18n, initialize it once:

import { createI18n } from "flat-i18n";
import texts from "./texts.json";

createI18n(texts, "en");

This should be done:

  • at application bootstrap
  • before server handlers
  • before rendering (SSR)

Server usage

Use getText anywhere — server, edge, scripts, or metadata generation.

import { getText } from "flat-i18n";

const title = getText("seo.title", "es");

Behavior

  • Missing key → returns the key
  • Missing locale → falls back to the default locale
  • Not initialized → throws an explicit error

React usage (controlled, optional)

flat-i18n does not manage the language state.

Your application owns the selected language (user preference, storage, API, etc.) and passes it to the provider.

App-level language state (example)

import { createContext, useContext, useState } from "react";

const AppLangContext = createContext(null);

export function AppLangProvider({ children }) {
  const [lang, setLang] = useState("en");

  return (
    <AppLangContext.Provider value={{ lang, setLang }}>
      {children}
    </AppLangContext.Provider>
  );
}

export function useAppLang() {
  return useContext(AppLangContext);
}

Wiring flat-i18n

import { I18nProvider } from "flat-i18n/react";
import { useAppLang } from "./AppLangContext";

function AppShell({ children }) {
  const { lang } = useAppLang();

  return (
    <I18nProvider currentLang={lang}>
      {children}
    </I18nProvider>
  );
}

Using translations in components

import { useI18n } from "flat-i18n/react";

function Header() {
  const { t } = useI18n();
  return <h1>{t("app.name")}</h1>;
}

Changing the app language automatically updates all translations. No routing. No reloads.

Use it in components:

import { useI18n } from "flat-i18n";

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

<h1>{t("app.name")}</h1>
<button onClick={() => setLocale("es")}>ES</button>

What flat-i18n is NOT

  • ❌ No pluralization engine
  • ❌ No string interpolation
  • ❌ No routing integration
  • ❌ No async loading
  • ❌ No opinionated structure

These features can be built on top, not baked in.


Philosophy

flat-i18n follows three simple rules:

  1. Explicit is better than implicit
  2. Boring code scales better
  3. You should understand the entire library in under 5 minutes

License

MIT © Exagon-Soft


Roadmap (non-binding)

  • v0.2.0 — string interpolation helpers
  • v0.3.0 — locale persistence utilities
  • v1.0.0 — API freeze

If you like this approach, use it, fork it, or build on top of it.

flat-i18nthe boring i18n that just works.