1

I am working on a multi-lingual site where the data source has multiple language versions. I want to retrieve the items of multilist based on the language parameter passed.

Sitecore GraphQL query:

{
  item(path: "/sitecore/content/Global/Components/Navigation/CarsMenu", language: "de-DE") {
    children {
      ... on CarMenu {
        title {
          value
        }
        category {
          targetItems {
            ... on CarMenuCategory {
              language {
                name
              }
              title {
                value
              }
            }
          }
        }
      }
    }
  }
}

Sitecore GraphQL Response:

{
  "data": {
    "item": {
      "children": [
        {
          "title": {
            "value": "Autos"
          },
          "category": {
            "targetItems": [
              {
                "language": {
                  **"name": "en"**
                },
                "title": {
                  "value": "SUVs"
                }
              },
              {
                "language": {
                  "name": "en"
                },
                "title": {
                  "value": "Sedans"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Issue:` Even though I passed the "de-DE" language, the multilist item is returning the fall back "en" in response even though there is a "de-DE" version exists.

So, my question is how to get the target items based on the language version?

0

A way to do this is to set the Sitecore Context Language to de-DE for the GraphQL query. Just add &sc_lang=de-DE to the querystring of the URL from the GraphQL endpoint. An now you can also remove the language in your query. And in the result al items are in "de-DE" or the version that you provide in the sc_lang parameter.

{
  item(path: "/sitecore/content/Global/Components/Navigation/CarsMenu") {
    children {
      ... on CarMenu {
        title {
          value
        }
        category {
          targetItems {
            ... on CarMenuCategory {
              language {
                name
              }
              title {
                value
              }
            }
          }
        }
      }
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.