npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@phrase/i18next-backend

v2.0.0

Published

Phrase Strings OTA i18next backend

Readme

i18nextPhraseBackend - Phrase Strings backend for i18next

Description

This small library implements an example backend for i18next 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
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 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 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
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 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.

npm install --save i18next-chained-backend

Web

Use i18next-http-backend as the fallback — no manual imports needed, files are loaded by URL:

npm install --save i18next-http-backend
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 with a dynamic import — Metro bundles all matching files without manual per-language imports:

npm install --save i18next-resources-to-backend
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.

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