Translations Module

Execute API actions pertaining to the binding engine’s translation store.

Add translations

Description:
Incorporate a dictionary of translations into the binding engine for a specified context.

{
    "type": "translations",
    "action": "get",
    "args": {
       "context": "person",
       "translations": {
           "firstName": "First Name",
           "lastName": "Last Name"
       }
    }
}

Get translations

Description:
Access the translated value associated with a specific translation key path in the binding engine.

{
    "type": "translations",
    "action": "get",
    "args": {
       "key": "person.firstName",
       "target": "$data.firstNameLable"
    }
}

Delete translations

Description:
Remove translations from the binding engine using the specified context key.

{
    "type": "translations",
    "action": "delete",
    "args": {
       "context": "myContext"
    }
}

Translate element

Description:
This function serves as a shorthand method for instructing the binding engine to parse a specified element. During this process, if there are translations associated with the element or its content, these translations will be integrated into the element at their designated locations. This action is a standard operation of the binding engine.

{
  "type": "translations",
  "action": "translate_elements",
  "args": {
    "element": "#my-element"
  }
}

String inflation

Description:
When you have a string containing translations, stored as a key in the crs binding translations store, and wish to populate that string with values from a dictionary, this method is used. It employs the string module’s inflate action, but the source string is retrieved from the translations store.

{
    "type": "translations",
    "action": "inflate",
    "args": {
        "key": "myTranslations.message",
        "parameters": {
            "code": "A11"
        },
        "target": "$data.message"
    }
}

In this scenario, consider a string like “${code} is valid”. The parameters object acts as the context model for inflation. The binding expression “${code}” signifies that the value of ‘code’ should be injected at this specified location in the string.