Localizations in Templates

Localizations are short text-snippets identified by a unique key, which have multiple translations into different languages. We can manage Localizations through the Localizations Service. In the context of Templates, we can use Localizations to create localize-able templates. In templates, we represent localizations with the helper function t. Take the following Template for example, where we use a Localization with key greeting:

{
    "name": "myTemplateName",
    "inputs": {
        "first_name": { "type": "string" }
    },
    "outputs": {
        "message": "{{t 'greeting'}} {{@inputs.first_name}},"
    }
}

In the original Template example, the greeting “Dear” was hardcoded. We have now replaced it with a greeting Localization.

This allows the Template Service to resolve the appropriate translated greeting dynamically. For example, if we resolve the Template in Dutch (NL), using the following snippet:

const result = await exh.templatesV2.resolve('myTemplateName', {
    language: 'NL',
    inputs: {
        first_name: 'John'
    }
});

The Template Service will lookup the greeting Localization in the Localization Service, which could contain something like:

{
    "key": "greeting",
    "text": {
        "EN": "Dear", 
        "NL": "Beste"
    }
}

Eventually, the resolver will put everything together correctly and respond with the following resolved Template:

Or, if we asked the resolver to resolve the Template in English:

The response would be:

Localizations with arguments

Because of grammar rules in certain languages, the order of words in a sentence can differ. Of course, this poses a problem if we use Localizations like in the example mentioned above. Sometimes a Localization will need to determine the exact placement of variable content in a string. Therefore Localizations can accept arguments.

Arguments can be used in Localization by using the placeholders {{place_holder_name}} .

With a Template:

Resolving for English:

will yield the following response:

Or resolving for Dutch (NL), will yield the following response: (with a different order of the values)

Last updated