OCAPI Localization

The Open Commerce API supports localized content.

Shop API 

The Shop API supports a single locale at a time. You can specify the locale by setting the *locale* parameter, which takes values in the format <language code>-<country code>. Otherwise, the Shop API uses the default locale of the site. 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:

1REQUEST:
2GET /dw/shop/v24_5/content/about_us?locale=en-US HTTP/1.1
3Host: example.com
4Accept: application/json
5
6RESPONSE:
7HTTP/1.1 200 OK
8Content-Length: 351
9Content-Type: application/json; charset=UTF-8
10
11{
12  "_v" : "24.5",
13  "_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
14  "description" : "It all started with a series of observations...",
15  "id" : "about-us",
16  "name" : "About Us",
17  "c_body" : "<h1 class=\"content-header\">About Us</h1><h2>It all started with a series of observations:</h2> ...",
18  "c_greeting" : "How are you?"
19}

Data API 

The Data API supports multiple locales at the same time. 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. Note: In Data API no locale fallback is performed.

The first example shows the default behavior, which returns a map of multiple localized values:

1REQUEST:
2GET /dw/data/v24_5/library/SiteGenesis/content/about-us HTTP/1.1
3Host: example.com
4Accept: application/json
5
6RESPONSE:
7HTTP/1.1 200 OK
8Content-Length: 569
9Cache-Control: max-age=0,no-cache,no-store,must-revalidate
10Content-Type: application/json;charset=UTF-8
11
12{
13  "_v" : "24.5",
14  "_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
15  "description" : {
16    "default" : "It all started with a series of observations..."
17  },
18  "id" : "about-us",
19  "link" : "https://example.com/s/-/dw/data/v24_5/libraries/SiteGenesis/content/about-us",
20  "name" : {
21    "default" : "About Us"
22  },
23  "c_body" : {
24    "default" : "<h1 class=\"content-header\">About Us</h1><h2>It all started with a series of observations:</h2> ...",
25    "de-DE" : "<h1 class=\"content-header\">Über uns</h1><h2>Alles begann mit einer Reihe von Untersuchungen:</h2> ..."
26  },
27  "c_greeting" :
28  {
29    "default" : "hello",
30    "en" : "Good day",
31    "en-US" : "How are you?",
32    "en-GB" : "How do you do?",
33    "de" : "Hallo",
34    "de-DE" : "Guten Tag",
35    "fr" : "Bonjour"
36  }
37}

The second example shows a response for an explicitly specified locale:

1REQUEST:
2GET /dw/data/v24_5/library/SiteGenesis/content/about-us?locale=en-US HTTP/1.1
3Host: example.com
4Accept: application/json
5
6RESPONSE:
7HTTP/1.1 200 OK
8Content-Length: 569
9Cache-Control: max-age=0,no-cache,no-store,must-revalidate
10Content-Type: application/json;charset=UTF-8
11
12{
13  "_v" : "24.5",
14  "_resource_state" : "ba4e84383e1790597e49eeee34b201633d80ed3f499992f5af11d639dd903a36"
15  "id" : "about-us",
16  "link" : "https://example.com/s/-/dw/data/v24_5/libraries/SiteGenesis/content/about-us",
17  "c_greeting" :
18  {
19    "en-US" : "How are you?"
20  }
21}

Attention!

The Open Commerce API (OCAPI) is now deprecated. The provisions described in our versioning and deprecation policy fully apply. For all new projects and major refactoring work, use B2C Commerce API (SCAPI) as the default REST API. For additional details, refer to Why Use SCAPI Instead of OCAPI.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!