Skip to content
@pyreon/i18n
fundamentals · translations

count === 1 is not a plural rule.

Translations, plurals, prices and dates that follow each language's own rules, and switch language live without a reload or a re-render. The message format is i18next's, so your JSON files come with you.

bun add @pyreon/i18n
Documentation
vs i18next
t() 12.0× fasterOne run, bun/JavaScriptCore, author-run.
plurals
every CLDR category_zero, _one, _two, _few, _many, _other, picked by Intl.PluralRules.
message format
i18next's keys{{name}}, _one/_other, context, $t(), ns:key.
iOS and Android
t(), plurals, locale switchLowered to a native runtime, asserted on device. Native targets are experimental; live switching and full CLDR plurals come in the next release.
Each language's own plural rules, switched live Schematic: t('files', { count }) renders '1 soubor', '3 soubory' and '5 souborů' in Czech, then the locale switches to Polish ('5 plików', the many form) and English ('5 files', '1 file'). A panel lists the message keys for the current language and lights the plural category Intl.PluralRules picked. T('FILES', { COUNT }) · CLDR PLURALS · LIVE LOCALE SWITCH count =135551 1 soubor3 soubory5 souborů5 plików5 files1 file i18n.locale.set(…) csplen messages[locale] files_onefiles_fewfiles_otherPluralRules('cs').select(1) → 'one'files_onefiles_fewfiles_otherPluralRules('cs').select(3) → 'few'files_onefiles_fewfiles_otherPluralRules('cs').select(5) → 'other'files_onefiles_fewfiles_manyfiles_otherPluralRules('pl').select(5) → 'many'files_onefiles_otherPluralRules('en').select(5) → 'other'files_onefiles_otherPluralRules('en').select(1) → 'one' i18next's message format: {{count}}, _one / _few / _many / _other
  • 12.0× faster t() lookup than i18next 26BENCHMARKS.md §10, i18n row · overnight run, one run, bun/JavaScriptCore
  • 5.1× faster interpolation than i18nextBENCHMARKS.md §10, i18n row · i18next on its faster escapeValue: false path
  • 3.6× faster plural resolution than i18nextBENCHMARKS.md §10, i18n row · one run

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

The bugs you ship in your second language, gone.

  1. Plurals by the language, not by === 1

    Czech says 1 soubor, 3 soubory, 5 souborů. Polish says 22 pliki and 25 plików. t('files', { count }) asks Intl.PluralRules for the category and picks files_few or files_many for you.

  2. Switch language, nothing re-renders

    i18n.locale.set('pl') and every t(), price and date on screen rewrites its own text node. Components keep their state, inputs keep their caret.

  3. Formats live inside the message

    Write Total: {{amount, currency}} or Seen {{n, relativetime, day}} in the translation. Translators move the number; you never concatenate.

  4. Same messages on the server

    @pyreon/i18n/core has no JSX and depends only on @pyreon/reactivity, so receipts, emails and edge functions use the same dictionaries as the UI.

the difference

You have written this ternary. So has everyone.

the usual shortcut

Right in English and German. Wrong in Czech, Polish, Russian, Ukrainian and Arabic.

const label = count === 1
  ? `${count} file`
  : `${count} files`

// cs: 1 soubor, 3 soubory, 5 souborů
// pl: 1 plik, 22 pliki, 25 plików
// ar: six forms, one of them for exactly two
with @pyreon/i18n

Each language lists the forms it has. The count picks one. A missing locale falls back.

import { createI18n } from '@pyreon/i18n'

const i18n = createI18n({
  locale: 'cs',
  fallbackLocale: 'en',
  messages: {
    en: { files_one: '{{count}} file', files_other: '{{count}} files' },
    cs: { files_one: '{{count}} soubor', files_few: '{{count}} soubory',
          files_other: '{{count}} souborů' },
    pl: { files_one: '{{count}} plik', files_few: '{{count}} pliki',
          files_many: '{{count}} plików', files_other: '{{count}} pliku' },
  },
})

i18n.t('files', { count: 3 })   // '3 soubory'
i18n.t('files', { count: 5 })   // '5 souborů'
i18n.locale.set('pl')           // every t() on screen updates in place
i18n.t('files', { count: 22 })  // '22 pliki'
coming from

Coming from i18next or react-intl?

Keep the JSON. Drop the init.

i18next
import i18next from 'i18next'

await i18next.init({
  lng: 'cs',
  fallbackLng: 'en',
  resources: {
    en: { translation: en },
    cs: { translation: cs },
  },
})

i18next.t('files', { count: 3 })   // '3 soubory'
await i18next.changeLanguage('en')
Pyreon

Checked with the same en/cs objects in both libraries: interpolation, _one/_few/_other, context, nested keys, $t() nesting and fallback give the same strings. Not supported: ordinal plurals, the {{- raw}} prefix and inline format options such as number(minimumFractionDigits: 2) (use a named format). i18next HTML-escapes values by default; Pyreon writes text into text nodes, so it does not.

import { createI18n } from '@pyreon/i18n'

const i18n = createI18n({
  locale: 'cs',
  fallbackLocale: 'en',
  messages: { en, cs },   // the same objects
})

i18n.t('files', { count: 3 })  // '3 soubory'
i18n.locale.set('en')          // synchronous, and reactive

ICU plurals become suffix keys.

react-intl
import { IntlProvider, useIntl } from 'react-intl'

const messages = {
  files: '{count, plural, one {# file} other {# files}}',
}

function Files({ count }: { count: number }) {
  const intl = useIntl()
  return <p>{intl.formatMessage({ id: 'files' }, { count })}</p>
}

<IntlProvider locale="en" messages={messages}>
  <Files count={3} />
</IntlProvider>
Pyreon

Pyreon does not parse ICU MessageFormat: each plural branch becomes its own _one/_other key, and {name} becomes {{name}}. Numbers, dates, relative time and lists go through the same Intl formatters as formatNumber and friends, as i18n.n(), d() and rt(), with l() for lists in the next release.

import { createI18n, I18nProvider, useI18n } from '@pyreon/i18n'

const i18n = createI18n({
  locale: 'en',
  messages: {
    en: { files_one: '{{count}} file', files_other: '{{count}} files' },
  },
})

const Files = (props: { count: number }) => {
  const { t } = useI18n()
  return <p>{t('files', { count: props.count })}</p>
}

<I18nProvider value={i18n}>
  <Files count={3} />
</I18nProvider>
try it

Change the language, then the count.

Pick Czech or Polish and try 1, 2, 5, 22 and 1.5. The plural category comes from Intl.PluralRules, the same call the package makes, and the price, date and relative time re-format for the new locale.

Try a count:

3 soubory

plural category: few

messages · cs
  • files_zeroŽádné soubory
  • files_one{{count, number}} soubor
  • files_few{{count, number}} soubory
  • files_many{{count, number}} souboru
  • files_other{{count, number}} souborů
formatters
  • n(1234.5, 'currency')1 234,50 Kč
  • d(date, 'long')14. března 2026
  • rt(-3, 'day')před 3 dny
  • n(0.42, 'percent')42 %

The category comes from Intl.PluralRules; each language lists only the forms it has. The formatters are memoized per locale and options.

benchmarks

t() 12× faster than i18next.

Every label calls t(), so the lookup cost is paid on every screen. i18next runs with escapeValue: false, its faster path, so both sides return the same raw string. The record lists no loss and no tie for i18n. The date row compares different default styles, so read it as indicative.

vs i18next 26.5.11 · bun/JavaScriptCore, one process per operation and libraryPyreonrival · lower is better
  • t() lookup
    win12.0×
  • interpolation
    win5.1×
  • plural
    win3.6×
  • number format
    win3.1×
  • date format
    win2.7×
Apple M3 Max · record of 2026-11-05 · overnight run, one run · author-run, syntheticFull method, every loss →
what's included

The whole translation layer, in one instance.

  • t(key, values) Reactive: read it in JSX and the text node updates when the locale or the messages change.
  • CLDR plurals _zero through _many per language, plus an explicit _zero for "No files" and your own pluralRules.
  • n(), d(), rt() Numbers, currency, dates and relative time, with each Intl formatter cached per locale and options.
  • Inline format specs {{when, date}}, {{n, relativetime, day}} and your own named formats, such as {{amount, currency}}, inside the message.
  • l() and dir()next release Lists in code or as {{people, list}}, and rtl for Arabic or Hebrew, ready for <html dir>.
  • Context and defaults { context: 'female' } tries friend_female first; defaultValue covers a key nobody translated yet.
  • Namespaces on demand t('checkout:title') with a loader; two concurrent loads of one namespace make one request.
  • <Trans> Puts JSX inside a translation: <bold>rich</bold> maps to your component, with t read from the provider.
  • Typed keys, opt in createI18n<typeof en>() turns t('nav.hoem') into a compile error.
  • Devtools subpath @pyreon/i18n/devtools lists live instances and their loaded locales, held by WeakRef.
recipes

Things to build with it.

Load a namespace when the route needs it

Ship only the strings the page uses. Concurrent loads of the same namespace share one request, and t() updates when it lands.

const i18n = createI18n({
  locale: 'de',
  fallbackLocale: 'en',
  loader: (locale, ns) =>
    import(`./locales/${locale}/${ns}.json`).then((m) => m.default),
})

await Promise.all([
  i18n.loadNamespace('checkout'),
  i18n.loadNamespace('checkout'),   // same promise, no second fetch
])

i18n.t('checkout:title')               // 'Kasse'
i18n.t('checkout:items', { count: 2 }) // '2 Artikel'
Translate a receipt email on the server

The /core entry has no JSX. The same dictionaries render in a worker, with currency and date formatted for the reader.

import { createI18n } from '@pyreon/i18n/core'

const eur = { style: 'currency', currency: 'EUR' } as const
const mail = createI18n({
  locale: 'en',
  messages: {
    en: { receipt: 'Paid {{amount, eur}} on {{when, date}}' },
    de: { receipt: '{{amount, eur}} bezahlt am {{when, date}}' },
  },
  numberFormats: { en: { eur }, de: { eur } },
})

const when = new Date(Date.UTC(2026, 10, 11))
mail.t('receipt', { amount: 42, when })  // 'Paid €42.00 on Nov 11, 2026'
mail.locale.set('de')
mail.t('receipt', { amount: 42, when })  // '42,00 € bezahlt am 11.11.2026'
api

Eight runtime exports and one instance.

Every export has a reference page with its signature, an example and the mistakes people make with it.

create · 4
  • createI18n
  • interpolate
  • resolvePluralCategory
  • parseRichText
components · 4
  • I18nProvider
  • useI18n
  • I18nContext
  • Trans
on the instance · 11
  • t
  • n
  • d
  • rt
  • locale
  • loadNamespace
  • addMessages
  • exists
  • isLoading
  • loadedNamespaces
  • availableLocales
entry points · 3
  • @pyreon/i18n
  • @pyreon/i18n/core
  • @pyreon/i18n/devtools
types · 7
  • I18nOptions
  • I18nInstance
  • TranslationDictionary
  • NamespaceLoader
  • MessageKeys
  • TranslationParams
  • TypedTranslationKey
next release · 3
  • l
  • dir
  • TextDirection
good to know

Good to know before you start.

Give each language its own plural keys

The category is chosen per locale. A Czech dictionary with only _one and _other falls back to _other for 3, which reads wrong. Add _few and _many where the language has them.

Pluralize with count

count drives the plural choice; a number passed as n or value is interpolated but not pluralized. context and defaultValue are options too, not message variables.

Read formatters in reactive code

n(), d() and rt() read the locale signal. Call them in JSX, a computed or an effect and they re-format when the language changes.

Native plural rules cover 41 locales

From the next release, iOS and Android ship a CLDR plural table in the runtime: 41 locale tags from ar to zh, and English-style rules for anything else. On the web it is whatever Intl.PluralRules knows.

questions

What people ask first.

Can I keep my i18next JSON files?

For the common syntax, yes: {{name}}, _one/_other suffixes, context, nested keys, $t() and ns:key resolve the same way. Ordinal plurals, {{- raw}} and inline format options are the gaps.

Where does 12× come from?

The i18n row of the benchmark record: one process per operation and library, bun/JavaScriptCore, one run, i18next 26.5.11 configured with escapeValue: false so both libraries produce the same raw string. The date row is flagged: the two libraries pick different default date styles.

Does it escape HTML?

No. Pyreon writes translated text into text nodes, where markup is inert. If you put a translation into innerHTML, escape it yourself, or use <Trans> for real markup.

What happens to a missing key?

t() tries the current locale, then fallbackLocale, then defaultValue, and finally returns the key itself. onMissingKey lets you log it or return something else.

Ship the Polish version. Polish speakers will notice.

bun add @pyreon/i18n
Read the i18n guide