# @phrase/i18next-backend

> Phrase Strings OTA i18next backend

Latest version **2.0.1** (published 2026-10-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @phrase/i18next-backend
pnpm add @phrase/i18next-backend
yarn add @phrase/i18next-backend
bun add @phrase/i18next-backend
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2026-10-05 |
| First published | 2023-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 0 |
| Unpacked size | 25.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Phrase |
| Maintainers | phraseapp, docstun |
| Keywords | i18next, phrase, strings, over-the-air, ota |

## Links

- npm: https://www.npmjs.com/package/@phrase/i18next-backend
- Repository: https://github.com/phrase/i18next-phrase-backend
- Homepage: https://phrase.com
- Issues: https://github.com/phrase/i18next-phrase-backend/issues
- npm.io page: https://npm.io/package/@phrase/i18next-backend

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2026-10-05
- 2.0.0 — 2026-06-10
- 1.3.3 — 2026-03-09
- 1.2.0 — 2024-01-04
- 1.1.1 — 2023-08-31
- 1.1.0 — 2023-08-08
- 1.0.3 — 2023-05-16
- 1.0.2 — 2023-05-16
- 1.0.1 — 2023-05-16
- 1.0.0 — 2023-05-16

## README

# i18nextPhraseBackend - Phrase Strings backend for i18next

## Description

This small library implements an example [backend](https://www.i18next.com/overview/plugins-and-utils#backends) for [`i18next`](https://www.i18next.com/) which retrieves the translations from Phrase OTA releases. The distribution should be created for `i18next` platform.

## Usage

A demo project can be found at https://github.com/phrase/ota-web-demo

### Basic usage

```
npm install --save @phrase/i18next-backend
```

```javascript
import i18n from "i18next";
import { I18nextPhraseBackend } from "@phrase/i18next-backend";

i18n
  .use(I18nextPhraseBackend)
  .init({
    fallbackLng: 'en',
    backend: {
      distribution: 'DISTRIBUTION_ID',
      environment: 'YOUR_ENVIRONMENT_SECRET',
      appVersion: '1.0.0',
    }
  });
```

### Options

The backend accepts several options:

* `distribution` (required): The ID of your Phrase Strings OTA distribution
* `environment` (required): The environment token of your Phrase Strings OTA distribution. Different tokens exist for `development` (i.e. beta) and `production` environments
* `appVersion`: You can prevent some OTA releases from being serverd to certain app versions by providing minimum and maximum app version in Phrase Strings
* `cacheExpirationTime`: See [Caching](#caching) below
* `datacenter`: `Datacenter.EU` (default) or `Datacenter.US`. Selects the Phrase OTA datacenter
* `format`: By default this library uses the i18next format, if you use i18next v4 (for the new pluralization resolution strategy), set this to `i18next_4`
* `storage`: Custom async storage implementation (see [React Native](#react-native) below)

## React Native

`@phrase/i18next-backend` works in React Native when you provide an async storage implementation via the `storage` option. No React Native dependency is bundled. The package accepts any `AsyncStorage`-compatible storage implementation.

```
npm install --save @phrase/i18next-backend @react-native-async-storage/async-storage
```

```javascript
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { I18nextPhraseBackend } from '@phrase/i18next-backend';

i18n
  .use(I18nextPhraseBackend)
  .use(initReactI18next)
  .init({
    fallbackLng: 'en',
    backend: {
      distribution: 'DISTRIBUTION_ID',
      environment: 'YOUR_ENVIRONMENT_SECRET',
      storage: AsyncStorage,
    },
  });
```

Any storage that implements `getItem`, `setItem`, and `clear` returning Promises is accepted (e.g. [react-native-mmkv](https://github.com/mrousavy/react-native-mmkv) with a small adapter).

### react-native-web

For codebases that target both React Native and web via `react-native-web`, no platform-specific wiring is needed — passing `AsyncStorage` works on both targets since `@react-native-async-storage/async-storage` ships a web implementation backed by `localStorage`. Alternatively, omit `storage` entirely and the package auto-detects `localStorage` on the web build.

## Offline fallback

To serve bundled translations when the OTA fetch fails, chain this backend with a local fallback using [`i18next-chained-backend`](https://github.com/i18next/i18next-chained-backend).

```
npm install --save i18next-chained-backend
```

### Web

Use [`i18next-http-backend`](https://github.com/i18next/i18next-http-backend) as the fallback — no manual imports needed, files are loaded by URL:

```
npm install --save i18next-http-backend
```

```javascript
import i18n from 'i18next';
import ChainedBackend from 'i18next-chained-backend';
import HttpBackend from 'i18next-http-backend';
import { I18nextPhraseBackend } from '@phrase/i18next-backend';

i18n
  .use(ChainedBackend)
  .init({
    fallbackLng: 'en',
    backend: {
      backends: [I18nextPhraseBackend, HttpBackend],
      backendOptions: [
        { distribution: 'DISTRIBUTION_ID', environment: 'YOUR_ENVIRONMENT_SECRET' },
        { loadPath: '/locales/{{lng}}/{{ns}}.json' },
      ],
    },
  });
```

### React Native

Use [`i18next-resources-to-backend`](https://github.com/i18next/i18next-resources-to-backend) with a dynamic import — Metro bundles all matching files without manual per-language imports:

```
npm install --save i18next-resources-to-backend
```

```javascript
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import ChainedBackend from 'i18next-chained-backend';
import resourcesToBackend from 'i18next-resources-to-backend';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { I18nextPhraseBackend } from '@phrase/i18next-backend';

i18n
  .use(ChainedBackend)
  .use(initReactI18next)
  .init({
    fallbackLng: 'en',
    backend: {
      backends: [
        I18nextPhraseBackend,
        resourcesToBackend((language, namespace) =>
          import(`./locales/${language}/${namespace}.json`)
        ),
      ],
      backendOptions: [
        {
          distribution: 'DISTRIBUTION_ID',
          environment: 'YOUR_ENVIRONMENT_SECRET',
          storage: AsyncStorage,
        },
      ],
    },
  });
```

## Caching

The library is caching translations and won't check for new translations for 5 minutes. This can be configured by setting the `cacheExpirationTime` option in the backend configuration for testing purposes. It's recommended to use at least 5 minutes in production.

```javascript
i18n
  .use(I18nextPhraseBackend)
  .init({
    fallbackLng: 'en',
    backend: {
      distribution: 'DISTRIBUTION_ID',
      environment: 'YOUR_ENVIRONMENT_SECRET',
      appVersion: '1.0.0',
      cacheExpirationTime: 60 * 5, // time in seconds
    }
  });
```

## Releasing a new version

After merging dependency bumps or other changes that warrant a new release:

1. Bump the `version` field in `package.json` (and run `npm install` so `package-lock.json` picks up the new version) in a PR, e.g. "bump version to x.y.z".
2. Once that PR is merged to `main`, create a [GitHub release](https://github.com/phrase/i18next-phrase-backend/releases/new) with a tag matching the new version (e.g. `1.3.4`, no `v` prefix) targeting `main`.
3. Publishing the release triggers the [`release.yml`](.github/workflows/release.yml) workflow, which runs `npm run build` and `npm publish --provenance --access public` to push the package to npmjs.org.

---
_Source: https://npm.io/package/@phrase/i18next-backend · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
