Localization for POST requests
Persist Integration Objects in multiple languages and view localizedAttributes as a deferred link.
The POST command supports the Content-Language command, as well as the localizedAttributes NavigationProperty, to persist an IntegrationObject item in multiple languages. You can also use the Accept-Language header in your POST request to return the persisted items in their localized languages in the response to your POST request.
The localizedAttributes property represents a collection of localized entities that contain each Item Type's localized attributes. A localized property is any property annotated with IsLanguageDependent, such as the description property in Product. The table that follows describes how the presence or absence of localized properties in a request affects persistence. For example, the following POST request persists all category attributes in all available languages when you provide a localizedAttribute, the localizedAttribute's localized properties, and the Content-Language header in your request.
POST https://localhost:9002/odata2webservices/LocalizedProduct/Categories
Depending on whether a POST request contains all or some of the localization values, the system persists the provided values using the logic shown in the following table.
| localizedAttributes | localized properties | Content-Language header | Result | Example Payload |
|---|---|---|---|---|
| provided | provided | provided | Merges the results of localizedAttributes and localizedProperties; localizedAttributes takes precedence |
{
"code": "clothing",
"name": "Clothing Category 1",
"localizedAttributes": [{
"language": "en",
"name": "Clothing Category 2"
}]
}
|
| not provided | provided | provided | Stores the localized properties in the language that the Content-Language header specifies |
{
"code": "clothing",
"name": "Clothing Category"
}
|
| not provided | provided | not provided | Stores the localized properties in the default platform language |
{
"code": "clothing",
"name": "Clothing Category Default"
}
|
| provided | not provided | not provided | Stores all localizedAttributes |
{
"code": "clothing",
"localizedAttributes": [{
"language": "en",
"name": "Clothing Category"
}]
}
|
| provided | provided | not provided | Merges the results of localizedAttributes and localizedProperties; localizedAttributes takes precedence |
{
"code": "clothing",
"name": "Clothing Category 1",
"localizedAttributes": [{
"language": "en",
"name": "Clothing Category 2"
}]
}
|
| provided | not provided | provided | Stores all localizedAttributes |
{
"code": "clothing",
"localizedAttributes": [{
"language": "en",
"name": "Clothing Category 2"
}]
}
|
Content-Language and Accept-Language Headers
| Scenario | Content-Language | Accept-Language | Language used to persist | Language used to retrieve persisted item |
|---|---|---|---|---|
| Valid Content-Language and Accept-Language headers | en | de | en | de |
| Valid Content-Language header only | en | en | en | |
| No language header provided | platform's default language | platform's default language | ||
| Valid Accept-Language header only | de | platform's default language | de |
If the Content-Language or Accept-Language header value does not exist in the platform, the system does not persist the item and returns a 400-Bad Request error similar to the following. In the example error response, en is the platform default language and invalidLanguageTagFromLanguageHeader is the invalid language provided in the Content-Language or Accept-Language header.
{
"error":
{
"code": "invalid_language",
"message":
{
"lang": "en",
"value": "The language provided [invalidLanguageTagFromLanguageHeader] is not available."
}
}
}