How to translate the ProductOption values with the GraphQL API ?

Highlighted
New Member
1 0 0

Hello,

Context:
Let's consider that I have one product with two options, the size [1cm, 2cm, 5cm, 10cm] and the color ['red', 'white']. I would like to translate the values of the color with the GraphQL API. 

Translating the name of the options ("size" and "color") was pretty easy. I first get the ID of the ProductOption. Then get its translatableContent.  Lastly, I send the translation with a mutation.

 

query($product_id: ID!) {
  product(id: $product_id) {
    options {
      id
      name
      position
      values
    }
  }
}

query($id: ID!) {
  translatableResource(resourceId: $id) {
    translatableContent {
      key
      value
      locale
      digest
    }
  }
}

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

 

 

Issue:
However, this only works for the name of the options. I would like to do the same things with the values. For instance, to translate "red" and "white" into "rouge" and "blanc". The only solution I find so far is to send a request for each ProductVariant. This means to send one request for each combination of the options. In this example: 
- "1cm / "red" -> translate option2 into "rouge"
- "1cm / "white"-> translate option2 into "blanc"
- "2cm / "red"-> translate option2 into "rouge"
- "2cm / "white" -> translate option2 into "blanc"
- "5cm / red"-> translate option2 into "rouge"
- "5cm / white"-> translate option2 into "blanc"
- "10cm / red"-> translate option2 into "rouge"
- "10cm / white"-> translate option2 into "blanc"


In practice, I have dozens of sizes and several colors. Therefore, I need to make hundreds of requests, when only a few would be needed. Therefore, I guess there is a better way to do it, but I can't find how. Anyone know what is the optimized way to do it ?

0 Likes