Skip to main content

Localization API

The Localization API lets you translate strings, format numbers and dates, and read the buyer's language, country, and currency context. Use this API to build extensions that adapt their content and behavior to the customer's locale, including support for pluralization and dynamic values in translations.

Translation keys must be defined in static JSON locale files bundled with the extension. Dynamic runtime translation loading isn't supported.

  • Display translated content: Render UI strings in the customer's preferred language using translation keys defined in locale JSON files.
  • Format numbers and currency: Use shopify.i18n.formatNumber() to display numbers, prices, and quantities in the customer's locale format.
  • Show country-specific messaging: Read the customer's country from shopify.localization.country to conditionally display region-specific notices, shipping information, or promotions.
  • Handle pluralization: Use the count option in shopify.i18n.translate() to automatically select the correct plural form based on the customer's locale rules.
Support
Targets (24)

The shopify global object provides localization and translation utilities for customer account extensions. Access the following properties on shopify to translate strings, format values, and read the buyer's language and country context.

required

Utilities for translating strings, formatting currencies, numbers, and dates according to the buyer's locale. Use this alongside localization to build fully localized extensions.

Anchor to localization
localization
required

The buyer's language, country, and locale context. Use this to adapt your extension to the buyer's region and display localized content.


  • Define a default locale file: Always include a locales/en.default.json file as the fallback. This ensures your extension displays meaningful content even when a translation for the customer's language isn't available.
  • Use dynamic values instead of string concatenation: Pass variables through the translate() options object (for example, {{formattedPoints}}) rather than concatenating translated fragments. This keeps translations flexible across languages with different word orders.
  • Format numbers with shopify.i18n.formatNumber(): Don't manually format numbers with toLocaleString(). The built-in formatter respects the store's locale configuration and produces consistent results.
  • Guard against missing localization data: Check that shopify.localization.country and other localization properties are defined before using them. These values load asynchronously and may be undefined on the initial render.

  • The translate() method only supports the pluralization categories defined by the Unicode CLDR for the active locale (for example, one, other, few, many). Custom plural categories aren't supported.
  • Country and language values reflect the customer's current session context. They can't be overridden programmatically by the extension.

Was this page helpful?