Search…
Localization
Cortex supports localization through custom localized string properties. Localization for a string property can be enabled via string property options. Once enabled, you can write to and read from that property in any specified locale.

Specifying Locale

Via API

When making api requests, locale can be specified by a locale identifier via the Accept-Language header. The locale identifier consists of a 2 or 3 letter language tag optionally followed by a hyphenated region. For example, en, en-US, en-UK, etc.
Localized API Request (en_US)
1
$.ajax({
2
url: "https://api.dev.medable.com/example/v2/c_my_object",
3
type: "GET",
4
contentType: "application/json; charset=UTF-8",
5
dataType : "json",
6
xhrFields: {
7
withCredentials: true
8
},
9
headers: {
10
"Accept-Language": "en-US",
11
"Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
12
}
13
});
Copied!

Within Scripts

Within scripts, you can specify locale using the .locale() method for the given query cursor or insert/update operation. In scripts, the locale identifier must be separated by _. For example, en, en_US, en_UK, etc.
Localized Query Cursor
return org.objects.c_my_object.find({_id: '5d0552f04b373401003aba6a'}).locale('en_US').passthru()
Localized Insert Operation return org.objects.c_my_object.insertOne({c_greeting: 'hello'}).locale('en_US').execute()
Localized Update Operation return org.objects.c_my_object.updateOne({_id: '5d0552f04b373401003aba6a'}, {$set: {c_greeting: 'bonjour'}}).locale('fr_FR').execute()

Reading and Writing to a Localized String Property

Reading from and writing to a localized string property occurs in the locale specified. If a locale isn't specified, then the default locale for the organization is used.
For example, below is a localized c_greeting property in the object c_my_object, and a value is written to it while specifying the en_US locale.
Localized API POST (en_US)
Localized API Post (en_US)
1
$.ajax({
2
url: "https://api.dev.medable.com/example/v2/c_my_object",
3
method: "POST",
4
dataType : "json",
5
xhrFields: {
6
withCredentials: true
7
},
8
headers: {
9
"Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq",
10
"Accept-Language": "en-US"
11
},
12
data: {
13
"c_greeting": "hello"
14
}
15
}).done(function(data) {
16
// ...
17
});
Copied!
When requesting that instance of c_my_object in the en_US locale, we can expect to always receive the c_greeting of "hello".
However, if we specify a different locale, we can write additional values to that property. For example, below we update that property with a value while specifying the locale "fr-FR"
Localized API POST (fr_FR)
1
$.ajax({
2
url: "https://api.dev.medable.com/example/v2/c_my_object/5d0552f04b373401003aba6a",
3
method: "PUT",
4
dataType : "json",
5
xhrFields: {
6
withCredentials: true
7
},
8
headers: {
9
"Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq",
10
"Accept-Language": "fr-FR"
11
},
12
data: {
13
"c_greeting": "bonjour"
14
}
15
}).done(function(data) {
16
// ...
17
});
Copied!
Now, depending on the locale we specify, we can retrieve different values for that same property when getting that c_my_object instance.
Localized API Request (en_US)
Response (en_US)
Localized API Request (fr_FR)
Response (fr_FR)
1
$.ajax({
2
url: "https://api.dev.medable.com/example/v2/c_my_object",
3
type: "GET",
4
contentType: "application/json; charset=UTF-8",
5
dataType : "json",
6
xhrFields: {
7
withCredentials: true
8
},
9
headers: {
10
"Accept-Language": "en-US",
11
"Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
12
}
13
});
Copied!
1
{
2
"data": [
3
{
4
"_id": "5d0552f04b373401003aba6a",
5
"c_greeting": "hello",
6
"object": "c_my_object"
7
}
8
],
9
"hasMore": false,
10
"object": "list"
11
}
Copied!
1
$.ajax({
2
url: "https://api.dev.medable.com/example/v2/c_my_object",
3
type: "GET",
4
contentType: "application/json; charset=UTF-8",
5
dataType : "json",
6
xhrFields: {
7
withCredentials: true
8
},
9
headers: {
10
"Accept-Language": "fr-FR",
11
"Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
12
}
13
});
Copied!
1
{
2
"data": [
3
{
4
"_id": "5d0552f04b373401003aba6a",
5
"c_greeting": "bonjour",
6
"object": "c_my_object"
7
}
8
],
9
"hasMore": false,
10
"object": "list"
11
}
Copied!
This allows for translations to be provided to client applications seamlessly simply by specifying the appropriate locale.
Additionally, when a string property is localized, you may also include the optional locales property to retrieve all localized string values at once. Inside the locales property, each localized string property is represented by an array of documents containing each locale and value that have been written (e.g. {locale: 'en_US', value: 'hello'}).
Include Optional Locales Property
1
$.ajax({
2
url: "https://api.dev.medable.com/example/v2/c_my_object?include=locales",
3
type: "GET",
4
contentType: "application/json; charset=UTF-8",
5
dataType : "json",
6
xhrFields: {
7
withCredentials: true
8
},
9
headers: {
10
"Accept-Language": "en-US",
11
"Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
12
}
13
});
14
15
/* response
16
{
17
"data": [
18
{
19
"_id": "5d0552f04b373401003aba6a",
20
"c_greeting": "hello",
21
"locales": {
22
"c_greeting": [
23
{
24
"_id": "5d0552f0229d2f010075979b",
25
"locale": "es",
26
"value": "hola"
27
},
28
{
29
"_id": "5d06ba1cba9d3f010039c668",
30
"locale": "fr_FR",
31
"value": "bonjour"
32
},
33
{
34
"_id": "5d06ba26ba9d3f010039c6d4",
35
"locale": "en_US",
36
"value": "hello"
37
}
38
]
39
},
40
"object": "c_my_object"
41
}
42
],
43
"hasMore": false,
44
"object": "list"
45
}
46
*/
Copied!
Last modified 1mo ago