コンテンツへスキップ
Docs menuStrings / Moving from i18next or next-intl
On this page
  1. Bring your files
  2. What the import does with i18next JSON
  3. What changes in your code
  4. If you keep i18next as your runtime

Moving from i18next or next-intl

How Lefine imports your i18next or next-intl JSON (nested keys, _one/_other plurals, {{variables}}), what changes in your code, and what the CDN serves.

Your JSON files come in as they are. Lefine stores and serves ICU messages, the format next-intl already uses. For i18next files, the import turns the i18next plural forms into ICU when you import, and {{variables}} when you publish.

Bring your files

  • Upload: in the app's Keys tab, Import a file: one file per language and namespace. An i18next locales/en/common.json goes into the namespace common. See Upload files.
  • GitHub: connect the repo and Lefine finds the layout, including i18next's locales/{locale}/{namespace}.json. Changes in Lefine go back to the repo as a pull request, in the same files. See Connect GitHub or the CLI.
  • CLI: npx lefine strings push --file messages/en.json takes a file shaped { namespace: { key: text } }. A next-intl messages/en.json already has this shape.

What the import does with i18next JSON

In your fileIn Lefine
Nested objects: { "home": { "title": "Hi" } }One key per leaf, joined with dots: home.title. The CDN serves it nested again.
"items_one" + "items_other"One key items: {count, plural, one {# item} other {# items}}
_two, _few, _many (Russian, Arabic, ...)More branches of the same plural
_zeroAn exact =0 {...} branch (i18next uses _zero for 0 in every language)
"place_ordinal_one", _ordinal_two, ...One key place: {count, selectordinal, one {#st} two {#nd} ...}
{{count}} inside a plural form# (a literal # in the text is quoted)
{{name}}, {{- name}}Kept as written in Lefine. The published file has {name}

A set of plural forms becomes one key only when it has an _other form, all its forms are one kind (cardinal or ordinal), and no plain items key sits beside it. The import preview lists each plural it merges. If your app in Lefine already stores items_one and items_other as keys of their own, they stay as they are.

What is not converted:

  • {{user.name}} and {{price, currency}}: ICU has no dotted names and no i18next formats. The release preview blocks the publish and names each key. Rename the variable ({userName}), or write the format in ICU ({price, number, ::currency/EUR}).
  • Context keys (friend_male, friend_female): they stay as separate keys. In ICU you can write one {gender, select, male {...} female {...} other {...}}.
  • Nesting ($t(other.key)): the text is served as written. Read the other key in your code.

What changes in your code

With i18next and react-i18next:

tsx
// Beforeimport { useTranslation } from "react-i18next";const { t } = useTranslation("common");t("cart.items", { count: 3 });// Afterimport { useStrings } from "lefine/react";const t = useStrings("common");t("cart.items", { count: 3 }); // "3 items": the merged plural, same key, same count
  • <Trans> with numbered tags (<1>terms</1>) becomes a named tag in the text and t.rich: "Read the <a>terms</a>", then t.rich("terms", { a: (chunks) => <a href="/terms">{chunks}</a> }).
  • i18n.changeLanguage("de") becomes loading the other language: see React (Vite), or <Link locale="de"> in Next.js.
  • Setup (i18n.init, backends, detectors) goes. npx lefine init writes lefine.ts for your framework.

With next-intl, your messages are already ICU and keep their keys. npx lefine migrate rewrites useTranslations and getTranslations and lists the rest: see lefine migrate in the CLI reference.

If you keep i18next as your runtime

The CDN serves ICU, the format the lefine package reads. Plain i18next does not read ICU: pointed at the CDN (for example with i18next-http-backend), it shows a merged plural as written, {count, plural, one {# item} other {# items}}, and leaves a {name} unreplaced.

To keep your i18next code for now, format the texts with lefine/strings. It works anywhere and does not need React:

ts
import { createTranslator } from "lefine/strings";import { createStrings } from "lefine/server";const strings = createStrings({ project: "app_..." });const props = await strings.load("de", ["common"]);const t = createTranslator({ ...props, namespace: "common" });t("cart.items", { count: 3 }); // the German plural, formatted

An ICU plugin for i18next (such as i18next-icu) may also read these files. We have not tested it.

Next step · ContentContent types
Was this page helpful?