Skip to main content

Localization
API

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.

required

Details about the language of the buyer.

Was this section helpful?

Translating strings

/* See the locales/en.default.json tab for the translation keys and values for this example */
import '@shopify/ui-extensions/preact';
import {render} from 'preact';

export default async () => {
render(<Extension />, document.body);
};

function Extension() {
return (
<s-text>
{shopify.i18n.translate('welcomeMessage')}
</s-text>
);
}

You can access the current country of a customer to implement country specific logic.

Anchor to example-translating-strings-with-pluralizationTranslating strings with pluralization

You can use the count option to get a pluralized string based on the current locale.

Was this section helpful?

Getting the country of the customer

/* See the locales/en.default.json tab for the translation keys and values for this example */
import '@shopify/ui-extensions/preact';
import {render} from 'preact';

export default async () => {
render(<Extension />, document.body);
};

function Extension() {
const countryCode =
shopify.localization?.country?.value?.isoCode;

if (countryCode === 'CA') {
return (
<s-banner status="warning">
{shopify.i18n.translate(
'canadaPostWarningMessage',
)}
</s-banner>
);
}
}