Help with Translating Product Metafields using GraphQL API

Help with Translating Product Metafields using GraphQL API

succubusnl
Shopify Partner
4 0 0

I'm trying to use the GraphQL API to translate a product metafield in Shopify. I'm currently using the following GraphQL mutation:

 

mutation translationsRegister($resourceId: ID!, $translations: [TranslationInput!]!) {
  translationsRegister(resourceId: $resourceId, translations: $translations) {
    userErrors {
      message
      field
    }
    translations {
      key
      value
    }
  }
}

 

Here are the variables I'm using:

"variables": map[string]interface{}{
  "resourceId": fmt.Sprintf("gid://shopify/Product/%s", args.ProductID),
  "translations": JSON{
    "locale": args.Locale,
    "key": args.Target,
    "value": args.Translation,
    "translatableContentDigest": fmt.Sprintf("%x", bs),
  },
},

 

The query works well for translating fields like title and body_html, but I'm having trouble getting it to work for metafields.

 

Has anyone else encountered this issue or have any suggestions on how to make this work for metafields?

 

Thanks in advance for your help!

Reply 1 (1)

Eric-HAN
Shopify Partner
172 25 19

Hi there

is this helpful for you.

mutation {
  translationsRegister(resourceId: "gid://shopify/Metafield/xxxxxx", translations: [
    {
      key: "namespace.key",
      value: "translated value",
      locale: "es",
      translatableContentDigest: "digest_value"
    }
  ]) {
    userErrors {
      message
      field
    }
    translations {
      locale
      key
      value
    }
  }
}
- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee