Skip to main content

getAllTranslationsForAllLanguages()

type: (namespace?: string) => Promise<I18nKeylessAllTranslationsResponse | void>

Fetches every translation of every supported language in one call, for the project the init config points at. Where awaitForTranslation resolves one string in one language, this returns the whole dictionary.

import * as I18nKeyless from 'i18n-keyless-node';

const response = await I18nKeyless.getAllTranslationsForAllLanguages();

// response.data.translations is keyed by source text, then by language:
// { "Bonjour": { en: "Hello", es: "Hola" } }

It resolves to void rather than throwing when the request fails, so a failure to reach the API cannot take a server down. Check the result before reading it.

Why you would call it

  • Warm a cache at boot, so the first user request does not wait on the network.
  • Serve a dictionary to your own clients — a mobile app or a browser bundle that talks to your backend instead of to i18n-keyless directly.
  • Export or audit what has been translated so far.

namespace

type: string (optional)

Limits the payload to one namespace. With no argument you get the default namespace. Pass one when you have partitioned a project and only need the slice this process renders.

const checkout = await I18nKeyless.getAllTranslationsForAllLanguages('checkout');

Not to be confused with the config option

init accepts an option of the same name. That one is a function you supply to replace the API call entirely — for serving translations from your own backend:

I18nKeyless.init({
API_KEY: 'YOUR_API_KEY',
languages: { primary: 'fr', supported: ['fr', 'en'] },
// Called instead of i18n-keyless's own request
getAllTranslationsForAllLanguages: async () => myOwnBackend.fetchDictionary(),
});

Supply it, or supply API_KEY, or supply your own API_URL — the SDK needs exactly one of the three.