What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

BUGS : productVariant -> translation

Solved

BUGS : productVariant -> translation

Nolan_V
Shopify Partner
11 0 0

Hi, I wanted to get the translated Name of a productvariant using the 2024-04 version of the GraphQL api, so I used this request:

{
       productVariants(first: 1, query: "updated_at:>'2023-10-31T13:30:24Z'") {
              nodes {
                        product {
                               translations(locale: "en") {
                                value
                                }
                         title
                        }
                        translations(locale: "en") {
                                  value
                        }
                       displayName
                      }
            }
}

And when a variant has more than one option, the first one is not returned, as shown in the images below.

Nolan_V_0-1716362262771.png

 

And I don't know why, but I have an HTML element returned to the value of the product title translation.

Nolan_V_1-1716362262820.png

 



I don't know if it's a user problem or if it's coming from your side?

I also wanted to know if there was any way to get all the translations of every languages of a product variant, or at least do something like this:

translations(locale: "en AND fr") {

Accepted Solution (1)
ShopifyDevSup
Shopify Staff
1453 238 525

This is an accepted solution.

Hey @Nolan_V , sorry for the delay in getting back to you here. 

 

If it's still not returning all of the translated fields, I'd recommend reaching out to our support teams directly so we can take a closer look at the store details and see if we can replicate. 

 

- Kyle G. 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 5 (5)

ShopifyDevSup
Shopify Staff
1453 238 525

Hey @Nolan_V

 

Thanks for sharing your query and the screenshots. 

 

For the first question, with the first one not returned, what I would recommend here is to add in the id field as well as key fields. This way you'll be able to confirm the exact variant that is being returned and the specific field that corresponds with what value is being returned. 

 

For the second question with not knowing where that html text is coming from, adding in the key field as well should help clarify that. Since that is a product translation then it's most likely the translated html of the product description. 

 

For getting multiple languages in a single query, you can add multiple request. Using an Alias in your query will help here. 

 

Here's an example query addressing the points above! 

 

{
   productVariants(first: 1) {
       nodes {
           id
           German: translations(locale: "de") {
               key
               value
           }
           French: translations(locale: "fr") {
               key
               value
           }
           displayName
       }
   }
}

Hope that helps, 

 

- Kyle G. 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Nolan_V
Shopify Partner
11 0 0

Hi @ShopifyDevSup, Thank you for your response.

I added the ID and key fields, and I can confirm that the first option is not getting returned by the API. Here are the full request and the result: 

REQUEST :

Click to expand...
{
productVariants(first: 1, query: "updated_at:>'2023-10-31T13:30:24Z'") {
nodes {
product {
translations(locale: "en") {
locale
key
value
}
title
id
}
translations(locale: "en") {
locale
key
value
}
displayName
id
}
}
}

RESULT :

Click to expand...
{
"data": {
"productVariants": {
"nodes": [
{
"product": {
"translations": [
{
"locale": "en",
"key": "title",
"value": "NAMAST'HEY cotton hat!!"
},
{
"locale": "en",
"key": "body_html",
"value": "<p style=\"margin: 0px 0px 1em; line-height: 1.4; color: #212b36; font-family: -apple-system, BlinkMacSystemFont, 'San Francisco', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\"> The must-have for yogis to face the cold! <br></p>\n<p style=\"margin: 0px 0px 1em; line-height: 1.4; color: #212b36; font-family: -apple-system, BlinkMacSystemFont, 'San Francisco', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\"> Discover our NAMAST’HEY hat </p>\n<p style=\"margin: 0px 0px 1em; line-height: 1.4; color: #212b36; font-family: -apple-system, BlinkMacSystemFont, 'San Francisco', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\"> - Navy blue or taupe color, white “NAMAST’HEY” embroidery </p>\n<p style=\"margin: 0px 0px 1em; line-height: 1.4; color: #212b36; font-family: -apple-system, BlinkMacSystemFont, 'San Francisco', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\"> - Cotton hat One size &amp; mixed model.</p>"
}
],
"title": "Bonnet en coton NAMAST'HEY !!",
"id": "gid://shopify/Product/5645155762338"
},
"translations": [
{
"locale": "en",
"key": "option2",
"value": "test subject"
},
{
"locale": "en",
"key": "option3",
"value": "Big"
}
],
"displayName": "Bonnet en coton NAMAST'HEY !! - vert / matière test / XL",
"id": "gid://shopify/ProductVariant/35887119302818"
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 6,
"actualQueryCost": 6,
"throttleStatus": {
"maximumAvailable": 2000,
"currentlyAvailable": 1965,
"restoreRate": 100
}
}
}
}



Nolan_V
Shopify Partner
11 0 0

Up                                          

Nolan_V
Shopify Partner
11 0 0

Hi, I did not found a solution for this issue

ShopifyDevSup
Shopify Staff
1453 238 525

This is an accepted solution.

Hey @Nolan_V , sorry for the delay in getting back to you here. 

 

If it's still not returning all of the translated fields, I'd recommend reaching out to our support teams directly so we can take a closer look at the store details and see if we can replicate. 

 

- Kyle G. 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog