Options
Everything below goes in backend: { … } inside i18next.init().
The table is generated at documentation build time from the TSDoc in the
published type declarations of @localize-work/[email protected].
If an option is added to the SDK and not documented here, this site fails to
build.
| Option | Type | Required | Description |
|---|---|---|---|
projectSlug | string | yes | Project slug as it appears in CDN paths and API routes. |
cdnBaseUrl | string | yes | CDN origin, e.g. https://cdn.localize.work. |
version | string | — | Release to load: an immutable version like 'v3', or 'latest' (default). |
apiBaseUrl | string | — | API origin for saveMissing, e.g. https://api.localize.work. Missing keys are only reported when BOTH apiBaseUrl and apiKey are set. |
apiKey | string | — | Public (read/saveMissing) API key. Dev-only — never ship it enabled to prod. |
trackUsage | boolean | TrackUsageOptions | — | Report which keys the app looks up, so the editor can show unused keys. Dev/staging only. Needs apiBaseUrl and apiKey. true uses the defaults; an object adjusts them. In a browser, keys are only reported on the hosts in allowedHosts (by default localhost, 127.0.0.1 and [::1]); where there is no web address at all (server rendering, React Native) they are reported whenever this is on. Each key is sent at most once per page load. @see https://localize.work/docs/sdk/usage-tracking/ |
strict | boolean | — | When true, a 404 for a namespace file is reported as a load error. By default a 404 resolves to an empty resource: variant locales (en-FI over en) publish sparse files, so an absent namespace is a normal condition. |
fetchOptions | RequestInit | — | Extra fetch options merged into every CDN request (headers, cache, …). |
loadPath | LoadPath | — | Escape hatch overriding the whole CDN URL: a template with {{lng}} and {{ns}} placeholders, or a function (language, namespace) => url. |
onFailedLoad | (info: FailedLoadInfo) => void | — | Observability hook — called on every failed CDN load, including sparse 404s. |
Rules the table cannot express
Section titled “Rules the table cannot express”These are enforced at init() and throw synchronously, so a misconfiguration
fails at startup rather than as silent 404s at runtime. Every message is
prefixed [@localize-work/i18next-backend].
cdnBaseUrl is required unless loadPath is set
Section titled “cdnBaseUrl is required unless loadPath is set”projectSlug is always required — it identifies the project for saveMissing
even when you have overridden the URL entirely. cdnBaseUrl is only required
when loadPath is absent. Setting both is allowed: loadPath wins for reads.
Omitting both raises `cdnBaseUrl` must be a non-empty string.
apiBaseUrl and apiKey are all-or-nothing
Section titled “apiBaseUrl and apiKey are all-or-nothing”Passing exactly one of them is an init error, not a warning:
saveMissing needs BOTH
apiBaseUrlandapiKey— only one was provided. Omit both to disable missing-key reporting.
Passing neither is the normal production configuration: create() becomes a
silent no-op.
onFailedLoad never changes behaviour
Section titled “onFailedLoad never changes behaviour”It is an observability hook, nothing more. It fires on every failed CDN
load, including the sparse 404s that are a normal condition for
variant locales — so if you route it into an error
tracker, filter status === 404 or you will page yourself over correct
behaviour.
Its argument:
| Field | Type | Always present | Description |
|---|---|---|---|
url | string | yes | |
language | string | yes | |
namespace | string | yes | |
status | number | — | HTTP status when a response was received; absent on network errors. |
error | unknown | — | The thrown value on network/parse failures; absent on plain HTTP errors. |
strict only changes what a 404 means
Section titled “strict only changes what a 404 means”Default (false): a 404 resolves to an empty resource and i18next’s
fallbackLng chain supplies the values. With strict: true, a 404 calls back
with an error and no retry. Everything else about failure handling is
identical.
loadPath templating
Section titled “loadPath templating”The string form substitutes {{lng}} and {{ns}}, URL-encoding both.
The function form receives (language, namespace) and must return a complete
URL. When loadPath is set, the pointer is never fetched — you are responsible
for versioning.
backend: {projectSlug: 'your-project',loadPath: 'https://static.example.com/i18n/{{lng}}/{{ns}}.json',// or: loadPath: (lng, ns) => `https://static.example.com/i18n/${lng}/${ns}.json`,}