Skip to main content
Primer Checkout React Native SDK is currently in beta (v3.0.0-beta.1). The API is subject to change before the stable release.
usePrimerLocalization returns the locale that Primer Checkout uses for the text it draws, with functions to translate the SDK’s strings and to format amounts and dates in that locale. Use it to make text in your own UI match the language of the SDK components.

Signature

Import the hook with import { usePrimerLocalization } from '@primer-io/react-native'. LocalizationResult and TranslationParams are exported as types. The hook does not need PrimerCheckoutProvider. You can call it anywhere in your app.

Returns

TranslationParams is Record<string, string | number>.

t

t(key, params) looks the key up in the strings for locale. A key missing there falls back to English. A key missing in English too returns the key itself. Both fallbacks log a warning. params fills {{name}} placeholders in the string. When you pass params, a placeholder without a matching param stays in the text and a warning is logged. Without params, the string is returned as is.

formatCurrency

formatCurrency converts the amount from minor units with the currency’s number of decimals, which comes from currency data bundled with the SDK, and formats it with Intl.NumberFormat in locale. An unknown currency code is formatted with 2 decimals. If Intl.NumberFormat throws, the result is the number followed by the currency code, for example 10.50 EUR.

formatDate

formatDate passes options to Intl.DateTimeFormat. If formatting throws, the result is the date’s ISO string.

Usage

For a total of 1050 in EUR, this renders “Pay €10.50” on a device set to English. Amounts in the client session are in minor units, so pass them to formatCurrency as they are.
The string keys are internal to the SDK and are not a stable API. The SDK can change or remove keys between releases. For text you control, use the text props of the components, see What you can change.

How the locale is resolved

Primer Checkout reads the device locale from Intl.DateTimeFormat().resolvedOptions().locale and picks the first match:
  1. The device locale, if the SDK has strings for it, for example pt-BR.
  2. Its base language, for example de for a device set to de-AT.
  3. English, en.

Supported locales

The SDK has strings for 57 locales: ar, az, bg, bs, ca, cs, da, de, el, en, es, es-AR, es-MX, et, fa, fi, fil, fr, he, hi, hr, hu, hy, id, it, ja, ka, kk, ko, ku, ky, lt, lv, mk, ms, nb, nl, nl-BE, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sv, th, tr, uk, ur-PK, uz, vi, zh-CN, zh-HK, zh-TW. See Supported locales for the language names.

What you can change

To change one piece of text, use the text props of the component, such as label and placeholder on the card inputs, or title, subtitle, retryLabel and otherMethodLabel on the status screens.

See also

Supported locales

Language names for every locale

Status screens

Screens with text props you can set

Card inputs

Labels and placeholders of the card fields

Checkout data

Client session amounts to format