Localization
Localize Tokeflow Bridge SDK elements with 39 built-in language packs, any language tag, right-to-left fields, a default locale, and per-element translation overrides.
The Bridge SDK renders its secure fields with built-in copy — element labels, placeholders, and validation error messages. Localization lets you present that copy in your customer's language and tailor individual strings to match your product's voice, without touching the secure fields themselves.
The SDK ships 39 built-in translation packs (SDK 2.10.0+; earlier versions have en and pt-BR only). You set a default locale once at initialization — any language tag works — and, when you need finer control, override specific strings per element.
Tokeflow's secure fields run inside isolated, cross-origin iframes; card data is encrypted in the browser and never touches your servers. Localization changes only the copy rendered inside those fields — it never affects how data is collected or encrypted.
Setting the default locale
Pass locale to the SDK constructor to apply a language to every element you create. When omitted, the SDK defaults to 'en'.
import { TokeflowBridge } from '@tokeflow_com/bridge-js';
const tokeflow = new TokeflowBridge({
publicKey: 'pk_live_mer_xxx',
locale: checkoutLanguage, // e.g. 'pt-BR' or navigator.language; applies to every element
});
await tokeflow.init();Built-in languages
| Region | Codes |
|---|---|
| Default packs | en (default), pt-BR |
| Europe | es fr de it nl pl ru uk tr ro el cs hu sv da nb fi |
| Middle East (right to left) | ar he fa ur |
| South Asia | hi bn mr ta te |
| East and Southeast Asia | zh (Simplified) zh-TW (Traditional) ja ko th vi id ms fil |
| Africa | sw pcm (Nigerian Pidgin) |
Any language tag
locale accepts any language tag, so you can pass your checkout's selected language or navigator.language as it is. The most specific pack wins, and a tag without a pack falls back to en:
| You pass | Pack used |
|---|---|
es-MX, es-419, es-ES | es |
zh-CN, zh-SG, zh-Hans-HK | zh |
zh-TW, zh-HK, zh-MO, zh-Hant-TW, yue | zh-TW |
pt, pt-PT, pt-BR | pt-BR |
iw, in, tl, no, nn | he, id, fil, nb, nb |
| Anything without a pack | en |
resolveLocale(tag) returns the pack a tag will use, isRtlLocale(tag) says whether it is right to left, and SUPPORTED_LOCALES lists the 39 codes — for example to validate a language picker. In TypeScript, locale accepts any string; TokeflowLocale lists the 39 codes, so an exhaustive switch on it needs a case for each.
Drive locale from your application's own language setting (for example, a user preference or the negotiated Accept-Language). Set it once at init so every element you create later is consistent.
Right-to-left languages
For ar, he, fa and ur the SDK lays the card fields out right to left inside their iframes: labels and errors run right to left, while the card digits stay left to right. Your page's dir does not reach inside the iframes, so there is nothing to style there; your own style or theme rules for the same properties still win. The cardholder-name input gets dir="rtl" for these locales too. Set dir on your own page with isRtlLocale:
import { isRtlLocale, resolveLocale } from '@tokeflow_com/bridge-js';
document.documentElement.dir = isRtlLocale(checkoutLanguage) ? 'rtl' : 'ltr';
resolveLocale('zh-Hant-HK'); // 'zh-TW', the pack the fields will useThe cardholder-name element
The cardholder-name element is a native input on your page, not an iframe field. From SDK 2.10.0 it follows the locale too: its placeholder is the active pack's (Nome impresso no cartão in pt-BR, Como aparece en la tarjeta in es) instead of always Cardholder Name. English is unchanged, and an explicit placeholder still wins.
Switching language
The fields read the locale when they are created, and element.update() does not change it. To change language on a live checkout, unmount the elements and create them again with the new locale. The React card elements and <CardholderNameElement> do this themselves when their locale prop changes, so a language picker works without a key. translations are read at creation only, so a change to them alone needs a new key.
Payment instruction components
<BoletoInstructions> and <PixAutomaticInstructions> have en and pt-BR strings: any English tag (en, en-US, en-GB) shows English, and any other locale shows pt-BR.
The 39 packs make the bundle larger: from 2.10.0, tokeflow.min.js is about 43 KB gzipped (from 37.5 KB) and index.esm.js about 34 KB (from 27 KB). The pack is chosen at runtime, so a bundler cannot drop the unused ones.
Overriding strings per element
Every element accepts its own locale and a translations object. Use this to localize a single field or to replace specific strings — a custom label, a friendlier error message — while leaving everything else on the built-in pack.
const cardNumber = tokeflow.createCardNumberElement({
locale: 'pt-BR',
translations: {
number: {
label: 'Número do cartão',
errors: { invalid: 'Verifique o número do cartão' },
},
},
});
cardNumber.mount('#card-number');Any string you do not override falls through to the built-in pack for the active locale. You only specify what you want to change.
translations is a partial object. There is no need to provide a complete translation set — supply only the fields you want to override, and the rest are filled in from the built-in pack.
Precedence
When the same string is defined in more than one place, the SDK resolves it from the most specific source first:
- Per-element
translations— passed to acreate*Element()factory. Highest priority. - SDK-init
translations— passed to theTokeflowBridgeconstructor. Applies to every element. - Built-in pack — the
enorpt-BRstrings shipped with the SDK. The fallback for anything not overridden.
Resolution is per string, not per object: a per-element override for one label does not discard your init-level override of a different label — each string is resolved independently down the chain.
const tokeflow = new TokeflowBridge({
publicKey: 'pk_live_mer_xxx',
locale: 'pt-BR',
translations: {
// Applies to every element created from this bridge
number: { label: 'Cartão de crédito' },
},
});
await tokeflow.init();
// This element overrides the label again, just for itself
const cardNumber = tokeflow.createCardNumberElement({
translations: {
number: { label: 'Número do cartão' }, // wins for this element only
},
});Example: overriding the card-number label and error in pt-BR
This example sets pt-BR as the default locale, then customizes the card-number element's label and its "invalid" error message. Every other string — the expiry placeholder, the CVC label, and so on — comes from the built-in pt-BR pack.
import { TokeflowBridge } from '@tokeflow_com/bridge-js';
const tokeflow = new TokeflowBridge({
publicKey: 'pk_live_mer_xxx',
locale: 'pt-BR',
});
await tokeflow.init();
const cardNumber = tokeflow.createCardNumberElement({
locale: 'pt-BR',
translations: {
number: {
label: 'Número do cartão',
errors: {
invalid: 'Verifique o número do cartão',
},
},
},
});
const cardExpiry = tokeflow.createCardExpirationElement(); // built-in pt-BR
const cardCvc = tokeflow.createCardCvcElement(); // built-in pt-BR
cardNumber.mount('#card-number');
cardExpiry.mount('#card-expiry');
cardCvc.mount('#card-cvc');React
The same locale and translations props are available on the React element components.
import { CardNumberElement } from '@tokeflow_com/bridge-js/react';
function CardNumber() {
return (
<CardNumberElement
id="card-number"
locale="pt-BR"
translations={{
number: {
label: 'Número do cartão',
errors: { invalid: 'Verifique o número do cartão' },
},
}}
/>
);
}Set the default locale once on the provider so it applies to every element:
import { TokeflowProvider } from '@tokeflow_com/bridge-js/react';
<TokeflowProvider config={{ publicKey: 'pk_live_mer_xxx', locale: 'pt-BR' }}>
<YourApp />
</TokeflowProvider>;Inspecting the built-in packs
The built-in translation packs are exported as BUILTIN_TRANSLATIONS, and their codes as SUPPORTED_LOCALES. Import it to see the exact shape and the strings each locale provides — useful when deciding which keys to override.
import { BUILTIN_TRANSLATIONS, SUPPORTED_LOCALES } from '@tokeflow_com/bridge-js';
console.log(BUILTIN_TRANSLATIONS.en); // English pack
console.log(BUILTIN_TRANSLATIONS['pt-BR']); // Brazilian Portuguese pack
console.log(SUPPORTED_LOCALES.length); // 39Use BUILTIN_TRANSLATIONS as a reference, not as a base to mutate. To customize copy, pass a partial translations object to the SDK or an element and let the built-in pack supply the rest.
Related
- Quick Start — set up the SDK and mount your first element.
- Tokenization — exchange collected card data for a token reference.
- SDK Overview — the Bridge SDK at a glance.