Manage app translations with the GraphQL Admin API
This guide explains how to use the GraphQL Admin API to create and retrieve translated content for Shopify resources. It also covers how to retrieve translated content using the Storefront API. For example, you might add translations of product information and email notification templates using the GraphQL Admin API so a merchant can send customers email notifications in multiple languages. Those translations can then be retrieved by either the GraphQL Admin API or the Storefront API.
GraphQL Admin API translation access scopes
To use the GraphQL Admin API to create or retrieve translated content, your app needs to request the
write_translations access scopes for a Shopify store. For more information on requesting access scopes when your app is installed, see OAuth.
Storefront API translation header
To use the Storefront API to retrieve translated content, your app needs to use the
Accept-Language HTTP request header when sending queries. The following example header enables Spanish translations to be returned using the Storefront API:
GraphQL Admin API translatable resource types
For information about types of resources that are translatable, refer to the
TranslatableResourceType reference documentation.
You can use the following query to list each of the translatable types of resources that are available:
Storefront API translation resources
The following resources include properties that can be retrieved using the Storefront API:
You can use the translateableResources connection to retrieve a list of translatable resources, their translatable content, and their existing translations in various languages. You can also retrieve all translations for a locale, regardless of resource type.
- Retrieve a list of translatable resources by their type
- Retrieve translations for a resource type and locale
- Retrieve a single translatable resource by its ID
- Retrieve translations from a resource object
Retrieve a list of translatable resources by their type
The following query retrieves a list of translatable resources that are products. For each product, the query retrieves the content that can be translated in the
The response shows that the White T-Shirt product with the ID
"gid://shopify/Product/1" has content that can be translated, including its title and body HTML.
key field associates translatable content with its translations. The
value field shows the translatable content itself. The
digest field is the translatable content's unique identifier. When you create a translation, the mutation needs to include the translatable content's digest value in the translatableContentDigest field.
Retrieve translations for a resource type and locale
Like the example above, this query retrieves a list of products and their translatable content. This query also includes the
translations field for each product, which retrieves any existing translations.
The field takes the argument
locale, which specifies the language of the translations to retrieve. In the following example, the language is Spanish.
Retrieve a single translatable resource by its ID
The following query retrieves a single translatable resource by passing its ID in the
Retrieve translations from a resource object
If your app only needs to read translations, then you can query translations directly from a translatable resource object.
GraphQL uses mutations to create, update, or delete data in a database. Mutations do the equivalent function of the REST data-modifying action verbs, such as POST, PUT, and DELETE.
You can use the translationsRegister mutation to create new translations for a resource. When you create a translation, the mutation needs to include the translatable content's
digest value in the
translatableContentDigest input field.
The following table shows codes and descriptions for errors that you might see when you create translations:
||A resource with the specified ID doesn't exist.|
||There are too many translation keys for the resource. You can include up to 100 translation keys per mutation.|
||The key provided for the translation is invalid.|
||The value for the translation is invalid.|
||The translatable content doesn't match the original content on the resource.|
||The language code is invalid.|
||The locale code is invalid.|
Retrieving Storefront API translations
You can query the supported resources using the
Accept-Language HTTP header, to return translated content to the Storefront API.
The following example query returns translated content for Product title in Spanish:
You can use the translationsRemove mutation to remove translations from a resource. In the following example, the Spanish and Japanese title translations are removed from the product with the ID
The following are known translation limitations:
- A resource's
tagsfield can't be translated. For example, you can't translate a product's tags.
- The translation response that's returned for menu links and email and SMS notification templates doesn't include the
- If the merchant changes a product's
handle, then URL redirects for that product won't be supported for language-specific URLs.
- You can translate
metafieldsonly if they are publicly accessible.
- App proxies don't have multi-language support.