HaloStack Docs
Open App
Packages

i18n

Dependency-free, type-safe localization engine with no codegen — dictionaries are plain TypeScript.

@halostack/i18n is a dependency-free localization engine with no codegen step. Its dictionaries are plain TypeScript objects, which means tsc checks your translation keys and interpolation parameters for you — a missing key is a compile error, not a surprise at runtime. The React bindings are optional, so the core works anywhere. See the package's README.md for the full API and a wiring walkthrough.

Importing

The package is split into a typed core plus optional server and React layers. Import the subpath that matches where you're working.

Structure

The source mirrors that split between the typed core and the React layer:

  • src/define.ts and src/translate.ts — the typed core.
  • src/locales.ts — the registered languages.
  • src/server.ts (with utils/parse-accept-language.ts) — Accept-Language parsing.
  • src/context.tsx, src/provider.tsx, and src/client.ts — the React layer.
  • src/utils/ — helpers such as normalize-locale and type-guards.

Conventions

When you add a key, edit the dictionaries so that every locale stays in sync — because a missing key is a type error rather than a silent runtime fallback, the compiler holds you to it. Add a new locale with defineLang.

Tests are co-located as *.test.ts and run with bun test src/. That requires types: ["bun"] and @types/node, both already configured here. There's no build step: the strings ship as TypeScript.