Skip to main content

Utilities

The smaller exports of i18n-keyless-react: clearing the cache, validating a language, and fetching a whole language by hand.

clearI18nKeylessStorage

type: (storage: I18nConfig["storage"]) => Promise<void>

Removes every cached translation from the storage adapter you passed to init. It takes that adapter as its argument — it does not read the one held in the config, so you can also clear a storage the SDK is not currently using.

import { clearI18nKeylessStorage } from 'i18n-keyless-react';

await clearI18nKeylessStorage(window.localStorage);

The store the UI reads from is untouched, so already-rendered text stays as it is until the next fetch. To clear both, use the next function.

clearI18nKeylessStorageAndStore

type: () => Promise<void>

Clears the storage and resets the in-memory store, so components fall back to their source strings and refetch. Takes no argument: it uses the storage from your init config.

import { clearI18nKeylessStorageAndStore } from 'i18n-keyless-react';

// e.g. a "reset translations" button in a debug menu
await clearI18nKeylessStorageAndStore();

Reach for this when a user reports stale text after you have edited translations in the dashboard, and for the sign-out path of an app where translations are user-specific.

validateLanguage

type: (lang: Lang, config: I18nConfig) => Lang | undefined

Answers whether a language is usable with a given config, and returns the language to actually use. It returns undefined when the language is neither supported nor covered by the config's fallback.

import { validateLanguage } from 'i18n-keyless-react';

const chosen = validateLanguage(fromTheUrl, myConfig);
if (!chosen) {
// fall back to your own default rather than rendering an unsupported language
}

Use it when a language arrives from outside your app — a URL segment, a stored preference, an Accept-Language header. For turning an arbitrary BCP-47 tag into a supported code (zh-TWzh-Hant), see resolveLang instead.

getAllTranslationsFromLanguage

type: (targetLanguage: Lang, store: FetchTranslationParams, namespace?: string) => Promise<I18nKeylessResponse | void>

Fetches every translation for one language directly from the API, bypassing the store and the cache. Re-exported from i18n-keyless-core.

import { getAllTranslationsFromLanguage } from 'i18n-keyless-react';

const response = await getAllTranslationsFromLanguage('de', store);

This is the low-level call the SDK uses internally. In an application you almost always want getServerTranslations (server) or plain init (client), both of which cache. Use this one when you are building tooling around i18n-keyless — an export script, a translation audit — and want the raw payload.