--- title: Localization description: The API for localizing your extension. api_version: 2025-04 api_name: customer-account-ui-extensions source_url: html: https://shopify.dev/docs/api/customer-account-ui-extensions/2025-04/apis/localization md: https://shopify.dev/docs/api/customer-account-ui-extensions/2025-04/apis/localization.md --- # LocalizationAPI The API for localizing your extension. ## StandardApi The base API object provided to this and other `customer-account` extension targets. * i18n I18n required Utilities for translating content and formatting values according to the current `localization` of the user. * localization Localization required Details about the language of the buyer. ### I18n * formatCurrency 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. ```ts (number: number | bigint, options?: { inExtensionLocale?: boolean; } & NumberFormatOptions) => string ``` * formatDate 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. ```ts (date: Date, options?: { inExtensionLocale?: boolean; } & DateTimeFormatOptions) => string ``` * formatNumber 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. ```ts (number: number | bigint, options?: { inExtensionLocale?: boolean; } & NumberFormatOptions) => string ``` * 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. ```ts I18nTranslate ``` ```ts export interface I18n { /** * 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. * * @param options.inExtensionLocale - if true, use the extension's locale */ formatNumber: ( number: number | bigint, options?: {inExtensionLocale?: boolean} & Intl.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. * * @param options.inExtensionLocale - if true, use the extension's locale */ formatCurrency: ( number: number | bigint, options?: {inExtensionLocale?: boolean} & Intl.NumberFormatOptions, ) => 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. * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat0 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options * * @param options.inExtensionLocale - if true, use the extension's locale */ formatDate: ( date: Date, options?: {inExtensionLocale?: boolean} & Intl.DateTimeFormatOptions, ) => string; /** * 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. */ translate: I18nTranslate; } ``` ### I18nTranslate This defines the i18n.translate() signature. ```ts export interface I18nTranslate { /** * This returns a translated string matching a key in a locale file. * * @example translate("banner.title") */ ( key: string, options?: {[placeholderKey: string]: ReplacementType | string | number}, ): ReplacementType extends string | number ? string : (string | ReplacementType)[]; } ``` ### Localization * extensionLanguage This is the buyer's language, as supported by the extension. If the buyer's actual language is not supported by the extension, this is the fallback locale used for translations. For example, if the buyer's language is 'fr-CA' but your extension only supports translations for 'fr', then the \`isoCode\` for this language is 'fr'. If your extension does not provide french translations at all, this value is the default locale for your extension (that is, the one matching your .default.json file). ```ts StatefulRemoteSubscribable ``` * language The language the buyer sees in the customer account hub. ```ts StatefulRemoteSubscribable ``` ```ts export interface Localization { /** * The language the buyer sees in the customer account hub. */ language: StatefulRemoteSubscribable; /** * This is the buyer's language, as supported by the extension. * If the buyer's actual language is not supported by the extension, * this is the fallback locale used for translations. * * For example, if the buyer's language is 'fr-CA' but your extension * only supports translations for 'fr', then the `isoCode` for this * language is 'fr'. If your extension does not provide french * translations at all, this value is the default locale for your * extension (that is, the one matching your .default.json file). */ extensionLanguage: StatefulRemoteSubscribable; } ``` ### Language * isoCode The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code. ```ts string ``` ```ts export interface Language { /** * The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code. * * @example 'en' for English, or 'en-US' for English local to United States. * @see https://en.wikipedia.org/wiki/IETF_language_tag * @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 */ isoCode: string; } ``` ## use​Language() 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. ### Returns * Language ### Language * isoCode string The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code. ### Language * isoCode The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code. ```ts string ``` ```ts export interface Language { /** * The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code. * * @example 'en' for English, or 'en-US' for English local to United States. * @see https://en.wikipedia.org/wiki/IETF_language_tag * @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 */ isoCode: string; } ``` ## use​Extension​Language() Returns the language the buyer sees in the customer account hub. ### Returns * Language ### Language * isoCode string The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code. ### Language * isoCode The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code. ```ts string ``` ```ts export interface Language { /** * The BCP-47 language tag. It may contain a dash followed by an ISO 3166-1 alpha-2 region code. * * @example 'en' for English, or 'en-US' for English local to United States. * @see https://en.wikipedia.org/wiki/IETF_language_tag * @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 */ isoCode: string; } ``` ## use​I18n() Returns utilities for translating content and formatting values according to the current localization of the user. ### Returns * I18n ### 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 I18nTranslate 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. ### I18n * formatCurrency 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. ```ts (number: number | bigint, options?: { inExtensionLocale?: boolean; } & NumberFormatOptions) => string ``` * formatDate 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. ```ts (date: Date, options?: { inExtensionLocale?: boolean; } & DateTimeFormatOptions) => string ``` * formatNumber 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. ```ts (number: number | bigint, options?: { inExtensionLocale?: boolean; } & NumberFormatOptions) => string ``` * 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. ```ts I18nTranslate ``` ```ts export interface I18n { /** * 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. * * @param options.inExtensionLocale - if true, use the extension's locale */ formatNumber: ( number: number | bigint, options?: {inExtensionLocale?: boolean} & Intl.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. * * @param options.inExtensionLocale - if true, use the extension's locale */ formatCurrency: ( number: number | bigint, options?: {inExtensionLocale?: boolean} & Intl.NumberFormatOptions, ) => 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. * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat0 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#using_options * * @param options.inExtensionLocale - if true, use the extension's locale */ formatDate: ( date: Date, options?: {inExtensionLocale?: boolean} & Intl.DateTimeFormatOptions, ) => string; /** * 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. */ translate: I18nTranslate; } ``` ### I18nTranslate This defines the i18n.translate() signature. ```ts export interface I18nTranslate { /** * This returns a translated string matching a key in a locale file. * * @example translate("banner.title") */ ( key: string, options?: {[placeholderKey: string]: ReplacementType | string | number}, ): ReplacementType extends string | number ? string : (string | ReplacementType)[]; } ``` ## use​Translate() Returns the `I18nTranslate` interface used to translate strings. ### Returns * I18nTranslate ### I18nTranslate ### I18nTranslate This defines the i18n.translate() signature. ```ts export interface I18nTranslate { /** * This returns a translated string matching a key in a locale file. * * @example translate("banner.title") */ ( key: string, options?: {[placeholderKey: string]: ReplacementType | string | number}, ): ReplacementType extends string | number ? string : (string | ReplacementType)[]; } ``` ### Examples * #### Translating strings ##### React ```jsx /* 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', () => , ); function Extension() { const translate = useTranslate(); return ( {translate('welcomeMessage')} ); } ``` ##### JavaScript ```js /* See the locales/en.default.json tab for the translation keys and values for this example */ import {extension} from '@shopify/ui-extensions/customer-account'; export default extension( 'customer-account.order-status.block.render', (root, {i18n}) => { const welcomeMsg = i18n.translate( 'welcomeMessage', ); root.appendChild(root.createText(welcomeMsg)); }, ); ``` ##### locales/en.default.json ```json { "welcomeMessage": "Welcome to our store!" } ``` ## Examples Translating strings with pluralization You can use the count option to get a pluralized string based on the current locale. ### Examples * #### Translating strings with pluralization ##### Description You can use the count option to get a pluralized string based on the current locale. ##### React ```jsx /* See the locales/en.default.json tab for the translation keys and values for this example */ import { reactExtension, Banner, useApi, useTranslate, } from '@shopify/ui-extensions-react/customer-account'; export default reactExtension( 'customer-account.order-status.block.render', () => , ); function Extension() { const {i18n} = useApi(); const translate = useTranslate(); const points = 10000; const formattedPoints = i18n.formatNumber(points); // Translate the loyalty points message, using pluralization to differentiate messages const loyaltyPointsMsg = translate( 'loyaltyPoints', { count: points, formattedPoints, }, ); return ; } ``` ##### JavaScript ```js /* See the locales/en.default.json tab for the translation keys and values for this example */ import { extension, Banner, } from '@shopify/ui-extensions/customer-account'; export default extension( 'customer-account.order-status.block.render', (root, {i18n}) => { const points = 10000; const formattedPoints = i18n.formatNumber(points); // Translate the loyalty points message, using pluralization to differentiate messages const loyaltyPointsMsg = i18n.translate( 'loyaltyPoints', { count: points, formattedPoints, }, ); const app = root.createComponent(Banner, { title: loyaltyPointsMsg, }); root.appendChild(app); }, ); ``` ##### locales/en.default.json ```json { "loyaltyPoints": { "one": "You have {{formattedPoints}} loyalty point", "other": "You have {{formattedPoints}} loyalty points" } } ```