LogoLogo
  • Introduction
  • Features
  • Getting Started
    • Cortex User Guide
      • Organizations
      • Log in
      • Generate an API key
      • Make your first API request
      • Configure the org settings
      • Set up a data model
        • Create custom objects
        • Add custom properties
      • One-to-many relationships
      • Read and write data
      • Making a Request
      • Handling responses
      • Authentication
      • Two-factor authentication
      • Set third-party cookies
      • Connections
      • Upload files
      • Cortex iOS
      • Get started with Swift
      • Cortex service accounts
      • Cortex developer tools
      • Automated Account Notifications
  • Cortex API
    • Overview
    • Objects
      • Objects Overview
      • Organization
      • Account
      • Connections
      • Notifications
      • Stats
      • Logs
      • Export
      • Events
      • Room
    • Object Definition
      • Object Properties
        • Any
        • Binary
        • Boolean
        • Date
        • Document
        • File
        • Geometry
        • List
        • Number
        • ObjectId
        • Reference
        • String
    • Object Types
    • Access Control
    • Querying
      • Query Operators
      • Property Selection
      • Property Access
    • Aggregating
      • Aggregation Operators
    • Scripting
      • Script Types
      • Script Limits
      • ObjectId
      • CortexObject
        • Accounts
        • Views
      • Cursors
      • Operations
      • Script Modules
        • API Module
        • Base64 Module
        • Cache Module
        • Connections Module
        • Console Module
        • Consts Module
        • Counters Module
        • Crypto Module
        • HTTP Module
        • Logger Module
        • Notifications Module
        • Request Module
        • Response Module
        • SAML Module
        • Schemas Modules
        • Script Module
        • Session Module
        • Util.id Module
        • Util.ip Module
        • Util.paths Module
        • XML Module
        • Developer
        • Config
        • Renderer
        • SFTP
        • FTP
        • DB
          • Cursors
          • Driver
      • Static Methods
        • Accounts
        • Views
        • Cursors
      • Audit
      • Environments
      • HTTP Driver
      • Notifications
        • Firebase Cloud Messaging (FCM)
        • Tencent Push Notification Service Configuration
      • Televisit
      • Transforms
      • Localization
      • Available Javascript Libraries
    • Decorators
      • Runtime
        • Acl
        • As
        • Log
        • Profile
      • Static
        • Env
        • Job
        • Object
        • On
        • Policy
        • Route
        • Transform
        • Trigger
    • Expressions
      • Primer
      • Pipelines
      • Operators
      • Accumulators
      • Variables
      • Conditionals
      • Transforms
      • Triggers
      • On
      • Events
    • Faults
      • Fault Reference
  • Releases
    • Cortex Release Notes
      • Cortex API 2.28.3 (R3.4.6)
      • Cortex API 2.28.1 (R3.4.3)
      • Cortex API 2.27.2 (R3.4.1)
      • Cortex API 2.27.1 (R3.3.5)
      • SQL DB Connector 1.3.4 (R3.3.3)
      • Cortex API 2.26.2 (R3.3.1)
      • Cortex API 2.26.1 (R3.2.2)
      • Cortex API 2.26.0 (R3.2.1)
      • SQL DB Connector 1.3.3
      • Cortex API 2.25.0 (R3.1.1)
      • SQL DB Connector 1.3.2 (R3.1.0)
      • Cortex API 2.24.2 (R3.0.2)
      • SQL DB Connector 1.3.1 (R3.0.0)
      • Cortex API 2.24.1 (R2.3.3)
      • Cortex API 2.24.0 (R2.3.2)
      • SQL DB Connector 1.3.0 (R2.3.0)
      • Cortex API 2.23.0 (R2.2.4)
      • SQL DB Connector 1.2.0 (R2.2.0)
      • Cortex API 2.22.2 (R2.1.2)
      • Cortex API 2.22.1 and SQL DB Connector 1.1.1 (R2.0.1)
      • Cortex API 2.22.0
      • Cortex API 2.21.3
      • Cortex API 2.21.2
      • Cortex Web 4.16.0
      • Cortex Web 4.15.1
      • Cortex API 2.20.1
      • Cortex Web 4.14.0
      • Cortex Renderer 1.3.3
      • Cortex API 2.19.4
      • Cortex API 2.19.3 and Cortex Web 4.13.1
      • Cortex Renderer 1.3.2
      • Cortex API 2.19.1
      • Cortex API 2.18.0
      • Cortex API 2.17.6
      • Cortex API 2.17.5
      • Cortex API 2.17.4
      • Cortex API 2.17.3
      • Cortex API 2.17.2
      • Cortex API 2.17.1
      • Cortex API 2.16.0
      • Cortex API 2.15.9
      • Cortex API 2.15.8-1
      • Cortex 2.15.8
      • Cortex API 2.18.1
      • Cortex API 2.16.1
      • Cortex Renderer 1.3.1
      • Cortex Renderer 1.3.0
      • Cortex Renderer 1.2.2
      • Cortex Renderer 1.2.1
      • Cortex Renderer 1.2.0
    • Third-Party License Attribution

© 2025 Medable, Inc. All rights reserved.

On this page
  • Specifying Locale
  • Via API
  • Within Scripts
  • Reading and Writing to a Localized String Property

Was this helpful?

  1. Cortex API
  2. Scripting

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.

$.ajax({
    url: "https://api.dev.medable.com/example/v2/c_my_object",
    type: "GET",
    contentType: "application/json; charset=UTF-8",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Accept-Language": "en-US",
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
    }
});

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)

$.ajax({
    url: "https://api.dev.medable.com/example/v2/c_my_object",
    method: "POST",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq",
        "Accept-Language": "en-US"
    },
    data: {
        "c_greeting": "hello"
    }
}).done(function(data) {
    // ...
});

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"

$.ajax({
    url: "https://api.dev.medable.com/example/v2/c_my_object/5d0552f04b373401003aba6a",
    method: "PUT",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq",
        "Accept-Language": "fr-FR"
    },
    data: {
        "c_greeting": "bonjour"
    }
}).done(function(data) {
    // ...
});

Now, depending on the locale we specify, we can retrieve different values for that same property when getting that c_my_object instance.

$.ajax({
    url: "https://api.dev.medable.com/example/v2/c_my_object",
    type: "GET",
    contentType: "application/json; charset=UTF-8",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Accept-Language": "en-US",
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
    }
});
{
    "data": [
        {
            "_id": "5d0552f04b373401003aba6a",
            "c_greeting": "hello",
            "object": "c_my_object"
        }
    ],
    "hasMore": false,
    "object": "list"
}
$.ajax({
    url: "https://api.dev.medable.com/example/v2/c_my_object",
    type: "GET",
    contentType: "application/json; charset=UTF-8",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Accept-Language": "fr-FR",
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
    }
});
{
    "data": [
        {
            "_id": "5d0552f04b373401003aba6a",
            "c_greeting": "bonjour",
            "object": "c_my_object"
        }
    ],
    "hasMore": false,
    "object": "list"
}

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'}).

 $.ajax({
    url: "https://api.dev.medable.com/example/v2/c_my_object?include=locales",
    type: "GET",
    contentType: "application/json; charset=UTF-8",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Accept-Language": "en-US",
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
    }
});

/* response
{
    "data": [
        {
            "_id": "5d0552f04b373401003aba6a",
            "c_greeting": "hello",
            "locales": {
                "c_greeting": [
                    {
                        "_id": "5d0552f0229d2f010075979b",
                        "locale": "es",
                        "value": "hola"
                    },
                    {
                        "_id": "5d06ba1cba9d3f010039c668",
                        "locale": "fr_FR",
                        "value": "bonjour"
                    },
                    {
                        "_id": "5d06ba26ba9d3f010039c6d4",
                        "locale": "en_US",
                        "value": "hello"
                    }
                ]
            },
            "object": "c_my_object"
        }
    ],
    "hasMore": false,
    "object": "list"
}
*/

Last updated 3 years ago

Was this helpful?