The Open Commerce API supports localized content.
The Shop API supports a single locale
at a time. You can set it as header parameter
Accept-Language
with value defined at rfc2616. You
can also specify the locale by setting the locale
parameter, it overwrites the locale set by request header and takes values
in the format <language code>-<country code>.
Otherwise, the Shop API uses the default locale of the site. Please Note:
In Shop API the following locale fallback is performed: Locale (en-US)
> Language Locale (en) > Default locale (default). The following
example shows how you can explicitly specify a locale:
REQUEST:
GET /dw/shop/v20_10/content/about_us?locale=en-US HTTP/1.1
Host: example.com
Accept: application/json
RESPONSE:
HTTP/1.1 200 OK
Content-Length: 351
Content-Type: application/json; charset=UTF-8
{
"_v" : "20.10",
"_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
"description" : "It all started with a series of observations...",
"id" : "about-us",
"name" : "About Us",
"c_body" : "<h1 class=\"content-header\">About Us</h1><h2>It all started with a series of observations:</h2> ...",
"c_greeting" : "How are you?"
}
The Data API supports multiple locales
at the same time. You can set it as header parameter
Accept-Language
with value defined at rfc2616. You
can also specify a single locale, that overwrite the locale set by header
parameter. By default, localizable properties are returned as a map of all
available localized values keyed by the locale identifier. However, you
can explicitly specify a single locale by setting the
locale
parameter, which takes values in the format
<language code>-<country code>. If you explicitly
specify a locale, localizable properties are returned as a single map
entry. Please Note: In Data API no locale fallback is performed.
The first example shows the default behavior, which returns a map of multiple localized values:
REQUEST:
GET /dw/data/v20_10/library/SiteGenesis/content/about-us HTTP/1.1
Host: example.com
Accept: application/json
RESPONSE:
HTTP/1.1 200 OK
Content-Length: 569
Cache-Control: max-age=0,no-cache,no-store,must-revalidate
Content-Type: application/json;charset=UTF-8
{
"_v" : "20.10",
"_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
"description" : {
"default" : "It all started with a series of observations..."
},
"id" : "about-us",
"link" : "https://example.com/s/-/dw/data/v20_10/libraries/SiteGenesis/content/about-us",
"name" : {
"default" : "About Us"
},
"c_body" : {
"default" : "<h1 class=\"content-header\">About Us</h1><h2>It all started with a series of observations:</h2> ...",
"de-DE" : "<h1 class=\"content-header\">Über uns</h1><h2>Alles begann mit einer Reihe von Untersuchungen:</h2> ..."
},
"c_greeting" :
{
"default" : "hello",
"en" : "Good day",
"en-US" : "How are you?",
"en-GB" : "How do you do?",
"de" : "Hallo",
"de-DE" : "Guten Tag",
"fr" : "Bonjour"
}
}
The second example shows a response for an explicitly specified locale:
and it also overwrites the header parameter. REQUEST:
GET /dw/data/v20_10/library/SiteGenesis/content/about-us?locale=en-US HTTP/1.1
Host: example.com
Accept: application/json
Accept-Language: en-gb;q=0.8, en;q=0.7
RESPONSE:
HTTP/1.1 200 OK
Content-Length: 569
Cache-Control: max-age=0,no-cache,no-store,must-revalidate
Content-Type: application/json;charset=UTF-8
{
"_v" : "20.10",
"_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
"id" : "about-us",
"link" : "https://example.com/s/-/dw/data/v20_10/libraries/SiteGenesis/content/about-us",
"c_greeting" :
{
"en-US" : "How are you?"
}
}