Storefront API @inContext directive supports languages
API
Effective April 01, 2022
As of version 2022-04, the @inContext
directive in the Storefront API accepts a language
argument in addition to country
. If the requested language is active for the given country, as configured within the shop's Market settings, then the query will return translated values.
The list of available languages can be accessed with this query:
query Localization @inContext(country: CA, language: FR) {
localization {
# for the current country
availableLanguages {
isoCode
endonymName
}
# and for non-current countries
availableCountries {
isoCode
name
availableLanguages {
isoCode
endonymName
}
}
}
}
If an unsupported language or country is requested via @inContext
, the response will fall back to supported values. In all cases, the actual country and language context will be returned as a response extension.
{
"data": {
"productByHandle": {
"title": "Cat bed",
"variants": {
"edges": [
{
"node": {
"priceV2": {
"amount": "100.0",
"currencyCode": "CAD"
}
}
}
]
}
}
},
"extensions": {
"context": {
"country": "CA",
"language": "EN"
}
}
}
Learn more about supporting multiple languages on storefronts.