I18nit
⚡ Quick Reference
Package: @vielzeug/i18nit · Category: I18n
Key exports: createI18n
When to use: Typed i18n with deterministic locale fallback, pluralization, async catalog loading, and reactive subscriptions.
@vielzeug/i18nit is a small localization runtime for typed translation keys, plural resolution, locale loading, and framework-friendly reactivity.
Installation
sh
pnpm add @vielzeug/i18nitsh
npm install @vielzeug/i18nitsh
yarn add @vielzeug/i18nitQuick Start
ts
import { createI18n } from '@vielzeug/i18nit';
import { createFormatter } from '@vielzeug/i18nit/format';
const i18n = createI18n({
locale: 'en',
fallback: 'en',
catalogs: {
en: {
greeting: 'Hello, {name}!',
inbox: {
zero: 'No messages',
one: 'One message',
other: '{count} messages',
},
},
fr: () => import('./locales/fr.json').then((m) => m.default),
},
});
await i18n.preload('fr');
await i18n.setLocale('fr');
const greeting = i18n.t('greeting', { name: 'Alice' });
const messages = i18n.tp('inbox', 3);
const fmt = createFormatter(i18n);
const price = fmt.currency(12.5, 'EUR');
const snapshot = i18n.getSnapshot();
const unsubscribe = i18n.subscribe(
(next) => {
console.log(next.locale, next.version);
},
{ immediate: true },
);
unsubscribe();
i18n.getSupportedLocales();Why I18nit?
- Minimal API:
t,tp,preload,setLocale,register,getSnapshot,subscribe,has,getSupportedLocales - Deterministic locale fallback chain resolution
- Typed leaf and plural branch keys with explicit APIs (
tandtp) - Explicit locale source model (static messages or async loaders)
- Framework-agnostic store primitives for React, Vue, Svelte, Solid, and others
- Zero dependencies
| Feature | I18nit | i18next | FormatJS |
|---|---|---|---|
| Bundle size | 1.4 KB | ~24 kB | ~16 kB |
| Typed key ergonomics | ✅ | Partial | Partial |
| Deterministic fallback chain | ✅ | ✅ | ✅ |
| Async locale preload | ✅ | ✅ | ✅ |
| Runtime snapshots + subscriptions | ✅ | ❌ | ❌ |
| External formatter bridge | ✅ (@vielzeug/i18nit/format) | Partial | ✅ |
| Framework agnostic | ✅ | ✅ | ✅ |
| Zero dependencies | ✅ | ❌ | ❌ |
Use I18nit when you want a compact, typed runtime with deterministic fallback behavior and framework-agnostic reactive state.
Consider i18next or FormatJS when you need larger ecosystem plugins, message extraction pipelines, or mature framework-specific integrations.
Features
- One runtime primitive:
createI18n(options) - Explicit translation methods:
t(leafKey, vars?)andtp(branchKey, count, options?) - Explicit locale lifecycle:
register,preload,setLocale - Reactive model through snapshots:
getSnapshot,subscribe - Deterministic fallback chain using active locale plus configured fallback locales
- Unified missing handling through
onMissing(info)for both key and interpolation misses - Formatting kept separate via
createFormatter(source)from@vielzeug/i18nit/format
Compatibility
| Environment | Support |
|---|---|
| Browser | ✅ |
| Node.js | ✅ |
| SSR | ✅ |
| Deno | ✅ |