Translations API: How to link METAFIELD, PRODUCT_OPTION, and PRODUCT_OPTION_VALUE from translatableResources API to their parent product?

Hi everyone,

We’re working on processing translations using the translatableResources API. For products, it’s straightforward - Shopify returns the resourceId like this:

{
“resourceId”: “gid://shopify/Product/20995642”,
“translatableContent”: [
{
“key”: “title”,
“value”: “Element”,
“locale”: “en”
},

]
}

However, we’re unsure how to associate translation entries like METAFIELD, PRODUCT_OPTION, and PRODUCT_OPTION_VALUE with their parent product (or other entities).

For example, when receiving:

resourceType: METAFIELD
resourceType: PRODUCT_OPTION
resourceType: PRODUCT_OPTION_VALUE

How can we determine which product or resource they belong to? The resourceId in these cases doesn’t seem to point directly to the product.

Any guidance or examples would be greatly appreciated!

Thanks

Hey @MasterDev :waving_hand: you’re right that this is a bit tricky. I did a bit of testing on my end, and it would depend on what type of integration you’re building, but you could build a function at code level that would run something like this to grab the translatableResources:

query GetProductOptions {
  translatableResources(first: 10, resourceType: PRODUCT_OPTION) {
    edges {
      node {
        resourceId  # This is the ProductOption ID
        translatableContent {
          key
          value
          digest
          locale
        }
      }
    }
  }
}

The resource ID that’s returned would be the product option ID. You could then run something like this to get the option value:

query GetProductFromOption($optionId: ID!) {
  node(id: $optionId) {
    ... on ProductOption {
      id
      name
      values
      optionValues {
        id
        name
        hasVariants
      }
    }
  }
}

Finally, you could then run a query using the plaintext option value itself to get the product info:

query GetProductFromOptionValue {
  productVariants(first: 10, query: "option1:'[option-value-here-without-brackets]'") {
    edges {
      node {
        id
        selectedOptions {
          name
          value
        }
        product {
          id
          title
          options {
            id
            name
            values
          }
        }
      }
    }
  }
}

Then, to double check that you’ve pulled the right parent product, you could compare the optionValue GID string from the one that was original output.

It’s definitely not the most ideal workflow though and it may not work for metafields in the same way. Translated resources are generally intended for apps that manage just the translation of those texts though, so generally the full context of the resource isn’t usually needed.

Just out of curiosity, could you let me know why you’re looking at pulling the parent products, etc? I’m definitely happy to see if I can help with some other workarounds or set up a feature request for sure!