Skip to main content

Localization

The API for localizing your extension.

The base API object provided to this and other customer-account extension targets.

required

Utilities for translating content and formatting values according to the current localization of the user.

Anchor to localization
localization
required

Details about the language of the buyer.

Returns the buyer's language, as supported by the extension. If the buyer's actual language is not supported by the extension, it will return the fallback locale used for translations.

Language

isoCode
string

The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code.

Anchor to useExtensionLanguage
useExtensionLanguage()

Returns the language the buyer sees in the customer account hub.

Language

isoCode
string

The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code.

Returns utilities for translating content and formatting values according to the current localization of the user.

I18n

formatCurrency
(number: number | bigint, options?: { inExtensionLocale?: boolean; } & NumberFormatOptions) => string

Returns a localized currency value.

This function behaves like the standard Intl.NumberFormat() with a style of currency applied. It uses the buyer's locale by default.

formatDate
(date: Date, options?: { inExtensionLocale?: boolean; } & DateTimeFormatOptions) => string

Returns a localized date value.

This function behaves like the standard Intl.DateTimeFormatOptions() and uses the buyer's locale by default. Formatting options can be passed in as options.

formatNumber
(number: number | bigint, options?: { inExtensionLocale?: boolean; } & NumberFormatOptions) => string

Returns a localized number.

This function behaves like the standard Intl.NumberFormat() with a style of decimal applied. It uses the buyer's locale by default.

translate

Returns translated content in the buyer's locale, as supported by the extension.

  • options.count is a special numeric value used in pluralization.
  • The other option keys and values are treated as replacements for interpolation.
  • If the replacements are all primitives, then translate() returns a single string.
  • If replacements contain UI components, then translate() returns an array of elements.

Returns the I18nTranslate interface used to translate strings.

I18nTranslate

This defines the i18n.translate() signature.

Examples
/* See the locales/en.default.json tab for the translation keys and values for this example */
import {
reactExtension,
Text,
useTranslate,
} from '@shopify/ui-extensions-react/customer-account';

export default reactExtension(
'customer-account.order-status.block.render',
() => <Extension />,
);

function Extension() {
const translate = useTranslate();
return (
<Text>{translate('welcomeMessage')}</Text>
);
}
Was this page helpful?