# 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](https://lefine.ai/en/docs/strings/import/).
- **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](https://lefine.ai/en/docs/strings/connect/).
- **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 file | In 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 |
| `_zero` | An 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
// Before
import { useTranslation } from "react-i18next";
const { t } = useTranslation("common");
t("cart.items", { count: 3 });

// After
import { 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)](https://lefine.ai/en/docs/strings/react/), or `<Link locale="de">` in [Next.js](https://lefine.ai/en/docs/strings/sdk/?fw=next).
- 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](https://lefine.ai/en/docs/reference/cli/) 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.

Source: https://lefine.ai/en/docs/strings/from-i18next/
