Docs JavaScript (Vanilla)

JavaScript (Vanilla)

Use i1n in any JavaScript or TypeScript project without a framework.

Setup

Install i1n as a dependency (npm install i1n) and run i1n init to configure your project. The CLI sets up nested JSON format in the locales/ directory.

The i1n SDK works in any JavaScript or TypeScript environment — Node.js, browser, Deno, or Bun. No framework or build tool dependencies are required.

Usage

Import init and t from i1n. Call init() with your locale and translation resources, then use t() to retrieve translated strings. Variables are interpolated with {var}, {{var}}, or %{var} syntax.

Use setLocale() to switch languages at runtime. Pluralization is supported via _zero, _one, and _other key suffixes. The generated i1n.d.ts file provides full autocomplete if you use TypeScript.

Bridge Mode

If your project already uses a custom translation function or lookup system, connect it with registerI1n((key, params) => yourFunction(key, params)). This adds i1n's type-safe autocomplete to any existing setup.

Bridge Mode works with any function that takes a key and optional parameters and returns a string. This makes i1n compatible with any custom i18n solution, regardless of framework.

main.js
import { init, t } from 'i1n'

init({
  locale: 'en_us',
  resources: {
    en_us: { greeting: 'Hello {name}' },
    es_es: { greeting: 'Hola {name}' }
  }
})

t('greeting', { name: 'World' }) // "Hello World"
Bridge Mode — main.js
import { registerI1n } from 'i1n'

// Connect any custom translation function
registerI1n((key, params) => myCustomLookup(key, params))

Related