Translating content for an online store

For this tutorial, you'll use the GraphQL Admin API to enable the es locale on your store, retrieve a product, and then translate the product's title. Finally, you'll publish the new locale and view the translated content on your store.

Requirements

This tutorial has the following requirements:

Step 1: Install the Shopify GraphiQL App

Install the Shopify GraphiQL app on your store. You can use the Shopify GraphiQL app to build and execute GraphQL queries and mutations on your store. When installing the GraphiQL app, make sure that you enable the translations and locales write access scope.

Step 2: Enable a locale

Use the shopLocaleEnable mutation to enable the es locale on your store. In the shopLocale response, include the locale, name, and published fields to verify that the locale has been successfully enabled.

By default, newly enabled locales are not published.

Run in GraphiQL

Step 3: Retrieve a translatable product

To retrieve the first product eligible for translation, use the translatableResources query with the parameters first: 1 and resourceType: PRODUCT. In the translatableContent response, include the key, value, digest, and locale fields. You need their response values to write the translation in the next step.

Run in GraphiQL

Step 4: Write a translation

Use the translationsRegister mutation to create a new translation for a translatable resource. When you create a translation, you need to include the translatable content's digest value in the translatableContentDigest field. A unique digest is returned from the translatableResources query for each translatableContent entry.

Run in GraphiQL

Note: Replace the value of id with the value of resourceId from the product that you queried in step 3.

Step 5: Publish the locale

You can publish a locale from the Shopify admin or by using the GraphQL Admin API. To learn more about publishing locales with the API, refer to Managing shop locales. Shops are limited to 5 published locales.

  1. In your development store's Shopify admin, go to Settings > Store Languages.

  2. In the Translated Languages section, click Publish next to the Spanish locale.

Step 6: Visit the online store to see your translation

To view the translation, navigate to the product's page on your online store. Make sure you add an es to your URL, for example, myshopifystore.com/es/products/great-shirt.

Additional information