Skip to content

Locales

The SDK translates error messages and amount-validation copy. Number formatting stays the same in every language.

Language is page-wide — one locale for every client on the page. Import helpers from @swapped/connect-sdk/locales. The client does not take locale options.

Set the language

ts
import { setLocale } from '@swapped/connect-sdk/locales'

await setLocale('es')

Call this before or after you create the client. English is ready immediately. Other languages load in the background and fall back to English until they are ready (or if loading fails).

preloadLocales(['es', 'de']) starts loading those languages without switching yet.

Supported languages: en, cs, da, de, es, et, fi, id, it, ja, nl, no, pt-BR, ro, sv, tr, vi. An unknown tag is accepted and falls back to English.

Language switcher

ts
import { getLocale, setLocale, SUPPORTED_LOCALES } from '@swapped/connect-sdk/locales'

for (const code of SUPPORTED_LOCALES) {
  // render a control that calls setLocale(code)
}

const current = getLocale()

In React, use useLocale() instead — see Locales (React).

Browser and session language

The SDK does not read the browser language on its own. If you want that:

ts
import { detectBrowserLocale, setLocale } from '@swapped/connect-sdk/locales'

void setLocale(detectBrowserLocale())

If you never call setLocale, a loaded session’s settings.language is used. Your explicit choice always wins.

Your own translations

Plug in your i18n stack. Return undefined to keep the SDK string.

ts
import { setTranslator } from '@swapped/connect-sdk/locales'

setTranslator((key, params) => myI18n.t(`swapped.${key}`, params))

Errors

error.message updates when the language changes. If you render your own copy, use error.code / error.apiCode and error.details instead of the message string.

Hosted widget windows (gateway, wallet popup, OAuth) follow the same language you set here.