what is translatableContentDigest and how can I generate Digest for translatable content

Highlighted
Shopify Partner
4 0 0

Hello, I am using GraphQL API for translating content for the product taking reference from.

 

 https://help.shopify.com/en/api/guides/multi-language/translating-content-api

 

But stucked in translatableContentDigest how can I has translatable content?

 

0 Likes
Highlighted
Tourist
6 0 3

I'd like to know as well.

This page talks about requiring generating a digest value when registering a translation but it doesn't say how: https://shopify.dev/tutorials/translating-content-for-online-store#step-4-write-a-translation

It seems like the example `digest` value is not base64 encoded, nor is it an `md5` hash -- the length of the digest in that example is 64 characters. It might be hashed using SHA-256?

Question to Shopify (or other knowledgable devs) can the digest be anything?

0 Likes
Highlighted
Tourist
6 0 3

Welp, I tried with `sha256` and I got the following error:

"userErrors": [
      {
        "code": "INVALID_TRANSLATABLE_CONTENT",
        "field": [
          "translations",
          "0",
          "translatableContentDigest"
        ],
        "message": "Translatable content hash is invalid"
      }
}

Searching for how one can create the digest comes with no goods! I only see docs that say "you need to provide the digest when registering translations". What's the deal, Shopify?

0 Likes
Highlighted
Tourist
6 0 3

Eureka, I figured it out thanks to the error message.

`translatableContentDigest` is a sha256 hash of the original content being translated.

If I was translating a product title (e.g. "Lemon Hawaiian Shirt") to French ("Chemise Hawaïenne Citron"), I'd have to get the value of the product's title ("Lemon Hawaiian Shirt"), hash that using sha256, then include that as the translatableContentDigest value in the GraphQL request:

 

mutation {
  translationsRegister(
    resourceId: "gid://shopify/Product/1234567890"
    translations: [
      {
        locale: "fr"
        key: "title"
        value: "Chemise Hawaïenne Citron"
        translatableContentDigest: "6aa3b98c0c2b71d6f588616bd4314227d11b1d9e7e031f1c0b0a8785f09eaac0"
      }
    ]
  ) {
    translations {
      key
      locale
      outdated
      value
    }
    userErrors {
      code
      field
      message
    }
  }
}

 

Same goes for all properties listed here: https://shopify.dev/tutorials/manage-app-translations-with-admin-api#graphql-admin-api-translatable-...

0 Likes