shopifyshopify-api

How to get other languages in translatableResources?


I'm working with translations in Shopify API. I have English set as the default language, but now I've also added Portuguese as a language and published it (I haven't added any translations though). However, when I call the GraphQL translateResources, it only returns the translatable content for English.

I'm using postman. This is my query

    query getTranslatableResources {
  translatableResource(resourceId: "gid://shopify/Product/7276207800399") {
    resourceId
    translatableContent {
      key
      value
      translatableContentDigest: digest
      locale
    }
  }
}

And this is the translatableContent object I get in the response:

"translatableContent": [
                {
                    "key": "title",
                    "value": "Cartridge Medium Taper Gauge 10 Tight Liner 5 needles (More than 10 month validity)",
                    "translatableContentDigest": "a73b0b1ad55fc98ab46fb1d41dcb10f7877747c4dc8ed5798129cce398cf0f30",
                    "locale": "en"
                },
                {
                    "key": "body_html",
                    "value": "test",
                    "translatableContentDigest": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
                    "locale": "en"
                },
                {
                    "key": "handle",
                    "value": "needle-3",
                    "translatableContentDigest": "deff7e9e149736d4e3ab2e3a1e8268c2015a9a4f54f42b67224dbd0e0f73b91c",
                    "locale": "en"
                },
                {
                    "key": "product_type",
                    "value": "",
                    "translatableContentDigest": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
                    "locale": "en"
                }
            ]

As you can see, I have added and published Portuguese as a language.

Shopify languages

What am I missing?


Solution

  • The TranslatableResource object only contains the resource's Global ID and the translatable content. It doesn't resolve to the product object itself, which is where you would be able to see it's translations.

    For the product in your example, you would need to query it directly or use the node interface, and then provide the locale as an argument to the translations field:

    {
      node(id:"gid://shopify/Product/7276207800399"){
        ... on Product{
            translations(locale:"pt-PT"){
            locale
            key
            value
          }
        }
      }
    }