The i18n library

An i18n library for JavaScript.

Comvi i18n is MIT-licensed and 7.6 kB min+gz with React, 5.6 kB core. CSP-safe.
No third-party code in your browser bundle.
No polyfills. Formatting comes from the runtime's own Intl.
Pairs with Comvi when you outgrow JSON files.

$npm install @comvi/react
GitHub ↗
Pick your stack
cart.tsCart.tsxCart.vueCart.svelteCart.tsxapp/[locale]/Cart.tsxcomponents/Cart.vue
1// cart: <a>{n, plural, one {# item} other {# items}}</a>
2import { createI18n } from "@comvi/core";
3import { icuCompiler } from "@comvi/core/icu";
4import { prepareTranslation } from "@comvi/core/rich-text";
5import en from "./locales/en.json";
6const i18n = createI18n({ locale: "en", messages: { en },
7 compiler: icuCompiler });
8await i18n.init();
9const { content } = prepareTranslation(i18n, {
10 i18nKey: "cart", params: { n: 3 },
11 components: { a: { tag: "a", props: { href: "/cart" } } },
12});
13// i18n.t("greeting.helo") → error TS2345:
14// Argument of type '"greeting.helo"' is not assignable to parameter of type '…'.
1// cart: <a>{n, plural, one {# item} other {# items}}</a>
2import { useI18n, T } from "@comvi/react";
3 
4export function Cart({ count }: { count: number }) {
5 const { t } = useI18n();
6 return (
7 <T i18nKey="cart" params={{ n: count }}
8 components={{ a: <a href="/cart" /> }} />
9 );
10}
11// t("greeting.helo") → error TS2345:
12// Argument of type '"greeting.helo"' is not assignable to parameter of type '…'.
1<script setup lang="ts">
2// cart: <a>{n, plural, one {# item} other {# items}}</a>
3import { useI18n, T } from "@comvi/vue";
4defineProps<{ count: number }>();
5const { t } = useI18n();
6// t("greeting.helo") → error TS2345:
7// Argument of type '"greeting.helo"' is not assignable to parameter of type '…'.
8</script>
9 
10<template>
11 <T i18nKey="cart" :params="{ n: count }">
12 <template #a="{ children }"><a href="/cart">{{ children }}</a></template>
13 </T>
14</template>
1<script lang="ts">
2 // cart: <a>{n, plural, one {# item} other {# items}}</a>
3 import { useI18n, T } from "@comvi/svelte";
4 
5 const { count }: { count: number } = $props();
6 const { t } = useI18n();
7 // $t("greeting.helo") → error TS2345:
8 // Argument of type '"greeting.helo"' is not assignable to parameter of type '…'.
9</script>
10 
11<T i18nKey="cart" params={{ n: count }}
12 components={{ a: { tag: "a", props: { href: "/cart" } } }} />
1// cart: <a>{n, plural, one {# item} other {# items}}</a>
2import { useI18n, T } from "@comvi/solid";
3 
4export function Cart(props: { count: number }) {
5 const { t } = useI18n();
6 return (
7 <T i18nKey="cart" params={{ n: props.count }}
8 components={{ a: (p) => <a href="/cart">{p.children}</a> }} />
9 );
10}
11// t("greeting.helo") → error TS2345:
12// Argument of type '"greeting.helo"' is not assignable to parameter of type '…'.
1"use client";
2// cart: <a>{n, plural, one {# item} other {# items}}</a>
3import { useI18n, T } from "@comvi/next/client";
4 
5export function Cart({ count }: { count: number }) {
6 const { t } = useI18n();
7 return (
8 <T i18nKey="cart" params={{ n: count }}
9 components={{ a: <a href="/cart" /> }} />
10 );
11}
12// t("greeting.helo") → error TS2345:
13// Argument of type '"greeting.helo"' is not assignable to parameter of type '…'.
1<script setup lang="ts">
2// cart: <a>{n, plural, one {# item} other {# items}}</a>
3defineProps<{ count: number }>();
4const { t } = useI18n();
5// t("greeting.helo") → error TS2345:
6// Argument of type '"greeting.helo"' is not assignable to parameter of type '…'.
7</script>
8<template>
9 <T i18nKey="cart" :params="{ n: count }">
10 <template #a="{ children }">
11 <NuxtLinkLocale to="/cart">{{ children }}</NuxtLinkLocale>
12 </template>
13 </T>
14</template>

Plurals need compiler: icuCompiler in your setup (Nuxt: comvi.icu: true).

Why Comvi i18n

Size, CSP and polyfills.

Size and the Content-Security-Policy come first, because those two are the hardest to change once an app ships. The third is Intl, which every runtime already ships.

5.61 kB core

Measured min+gz through the published exports map, with each binding's own cost below it. None of these five brings in third-party code, and every row is gated in CI: it cannot grow past a budget set 5 percent above its recorded baseline.

No unsafe-eval needed

No eval, no new Function, so a strict Content-Security-Policy needs no exception for the library.

No polyfills to ship

Intl is in every runtime the library supports, so the formatters are already there. The library binds them to the active locale.

Type-safe keys

Every key and parameter is a generated type.

The types come from your catalog, so the editor knows every key before the app runs, and a typo fails tsc instead of rendering a raw key on a page.

VS Code completing t("demo.interpolation.") with the three keys under it: body, label and title.
Key completion in VS Code, from the types the Vite plugin generates for the React example.
VS Code underlining t("greeting.helo") in red, with TypeScript's error 2345 in the hover: the key is not one of the catalog's keys.
A misspelled key in the same file: TypeScript's own error, before the app runs.
  • The Vite plugin generates TranslationKeys from your local JSON files each time one is saved
  • comvi typegen generates the same declarations from a Comvi project
  • A typo in a key or a missing ICU parameter fails tsc
Type safety in the docs
Also in the box

What else the library does.

ICU messages

plural, select and selectordinal in one message once you pass compiler: icuCompiler, with every plural form a language has: four in Polish, six in Arabic.

Docs
Tags

A <link> in a message becomes your own element through <T>. The translator moves the tag; your code decides what it renders.

Docs
Intl formatting

Numbers, dates, currency and relative time in the active locale, from the runtime’s own Intl.

Docs
Server rendering

The Next.js and Nuxt bindings load the request’s locale on the server and hand it to the client, so the first paint is already translated.

Docs
Plugins

A CDN loader, a locale detector, the in-context editor, or your own, each composed with .use().

Docs
The platform

JSON files forever, or Comvi when the team grows.

You can run @comvi/core with JSON files in your repo and never create an account. The platform adds an editor translators open on the page itself, a CDN redeployed a few seconds after the last edit, translation memory and a glossary.

See the platform
Install

Install the package for your stack.

$npm install @comvi/react

Migrate from i18nextMigrate from vue-i18n