Skip to content

i18next backend

@localize-work/i18next-backend is an i18next backend plugin. It fetches published JSON straight from the CDN and — in development only — reports missing keys back to the API.

It works in browsers and in Node 18+. It uses global fetch and has no HTTP dependency; i18next is its only peer dependency (^23 || ^24 || ^25 || ^26 || ^27). i18next 27 is supported from SDK 0.11.1 and itself needs Node 22 or later.

It also runs in React Native, Hermes included: it needs only the global fetch, and doesn’t use TextEncoder, URL or the DOM, which older Hermes releases lack. In-context editing needs a browser, so don’t import @localize-work/i18next-backend/in-context in a React Native app. If you turn on key usage tracking there, turn it on only in development builds: an app has no hostname to tell development from production by.

Terminal window
pnpm add i18next @localize-work/i18next-backend
# react apps: pnpm add react-i18next
i18n.ts
import i18next from 'i18next';
import { initReactI18next } from 'react-i18next';
import LocalizeBackend from '@localize-work/i18next-backend';
await i18next
.use(LocalizeBackend)
.use(initReactI18next)
.init({
lng: 'et',
fallbackLng: 'en',
ns: ['common', 'app'],
defaultNS: 'common',
backend: {
projectSlug: 'your-project',
cdnBaseUrl: 'https://cdn.localize.work',
},
});

The plugin is also exported as a named export, LocalizeBackend, if you prefer that to the default.

  • Resolves latest.json once per backend instance, then reads every locale and namespace at that one version, so a publish landing mid-startup cannot give you a half-and-half resource set.
  • Classifies failures for i18next’s retry logic: 2xx → data; 404 → empty resource (a normal condition for variant locales); other 4xx → error, no retry; 5xx and network errors → error, retry allowed.
  • Batches saveMissing reports per (locale, namespace) and posts them — only when both apiBaseUrl and apiKey are configured. See saveMissing.
  • No caching layer. It calls fetch. Use fetchOptions to hand the browser or Node cache your own directives; the CDN already sets long-lived Cache-Control on immutable paths.
  • No bundling or offline snapshot. If you need translations inside your build artifact, fetch them at build time and hand them to i18next as resources — the files are plain JSON with no auth.
  • No polling. Picking up a newer release means re-initialising i18next.
  • No writes other than saveMissing. Nothing in this package can change a translation.

cdnUrl() is exported so you can print what the backend will fetch:

import { cdnUrl } from '@localize-work/i18next-backend';
cdnUrl({ cdnBaseUrl: 'https://cdn.localize.work', projectSlug: 'your-project', version: 'v12' }, 'et', 'common');
// https://cdn.localize.work/your-project/v12/et/common.json

latestManifestUrl() and missingUrl() are exported for the same reason.

version defaults to 'latest', which follows the pointer. Pass an immutable version to freeze a deploy to an exact release:

backend: {
projectSlug: 'your-project',
cdnBaseUrl: 'https://cdn.localize.work',
version: 'v12', // exact release, never changes
}

A rollback on our side moves the pointer; pinned applications are unaffected in either direction. Inject the version at build time if you want deploy-locked translations without editing source.