Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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?
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?
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?
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-...
@mscheurich thanks for finding the hash algorithm 😃
For those who don't want to to generate hash themselves though, you can get them from existing content entities
{
translatableResource(resourceId: "gid://shopify/Product/1") {
resourceId
translatableContent {
key
value
digest
locale
}
translations(locale: "ja") {
key
value
locale
}
}
}
Will get you digest hash
{
"data": {
"translatableResource": {
"resourceId": "gid://shopify/Product/1",
"translatableContent": [
{
"key": "title",
"value": "my product title",
"digest": "df1570fdf4972ddb2e7224ee325a30d14794936eb3edec9bd3e78c37ac0b7509",
"locale": "en"
},
...
...
...
}
Here's how using Javascript
const original_product_title = 'A T-Shirt';
import crypto from 'crypto';
const shopify_digest = crypto.createHash('sha256').update(original_product_title).digest('hex');
console.log(original_product_title);
console.log(shopify_digest);
// A T-Shirt
// 2078e7240af94923f7d129a9c219e3210e4225be01705b1835b110cc56ff9417
Keep in mind the digest is of the untranslated value.
So my English Product.title gets digested.
And I send that digest to Shopify with my desired translated value.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024