Overview

In this article, we’ll go over how to use locales when writing your skills in the IDE.

 

In this Article

 

What are locales?

Locales are the language and region of the user and/or application context which generated an event, formatted as an ISO 639 language tag and an ISO 3166 region tag combined with a dash ("-").  
Example: "en-us"

The locale does not determine the language of the text a skill may display when it executes. Rather it helps an event determine if there's a skill associated with that language and region and then based on the event and skill code, whether or not the skill should run.

 

When to use locales

You should use locales if your organization uses multiple locales in PrecisionLender and you want your Andi skill to run for events that occur in specific, some, or all locales.

If a locale is not defined in the skillmanfiest.json file, the skill will default to English (en-us) for the locale.

For example, if your organization uses PrecisionLender in both English (en-us) and Spanish (es-es) and you'd like to write a skill for both language regions that displays a message when a new pricing scenario is added to an opportunity, then you should define the skill's locale as en-us and es-es so that the skill runs when that event occurs in both regions. Otherwise, it will only run for en-us events if you do not define a locale, or es-es events if you only define that locale. 

 

How to define locales

You will define locales in the skillmanifest.json file. Locales are case sensitive and will need to be entered using lowercase in the skillManifest and in any shouldIRun and run logic.

In the skillManifest.json

You will define locales as an array in the locales property. This will look like the following:

"description": "This is a description of your skill and/or keys", 
"skillConfigKeys": [],
"locales": ["en-us"]

Note: If checking the event payload, you may see the locale displayed as "en_us". However, when writing your skill, this should be modified to the standard "en-us".

Using our earlier example, we want to write a skill that displays a message when a user adds another pricing scenario to an opportunity in both our U.S. and Spain regions. The skillManifest would look like the following to define the locales:

"description": "This skill displays the following message in the Andi window when a user adds another pricing scenario to an opportunity: You've added a new scenario!/Has añadido un nuevo escenario!", 
"skillConfigKeys": [],
"locales": ["en-us", "es-es"]

In the shouldIRun.ts

You will then define the parameters for which your skill should run in the shouldIRun file.

For our example, we want the skill to run only if a new scenario has been added to the opportunity. Note: Locales can be used in the shouldIRun logic, but will not be for this example.

export function shouldIRun(skillContext: andiSkills.ISkillContext): Promise | boolean {
    
    let anEvent = skillContext.powers.andi.event.getApplicationEvent();
    let scenarioAdded = anEvent && anEvent.applicationEventName && anEvent.applicationEventName.startsWith("scenarioAdded");
    
    
    // if a scenario hasn't been added, don't run
    if(!scenarioAdded)
        return skillContext.powers.andi.shouldIRun.shouldIRunFalse(); 

    //otherwise the skill should run            
    return skillContext.powers.andi.shouldIRun.shouldIRunTrue();
}

In the run.ts

In the run.ts file, you will define what you want to happen when the skill runs. 

For our example, we want a field tag to appear when a new scenario is added to an opportunity. However, we want this field tag to display the message in the appropriate language, so we define two language variables using getLocale() from the skillContext based on the locale string.

let english = skillContext.getLocale() === "en-us"; 
let spanish = skillContext.getLocale() === "es-es"; 

Then, we define our field tag message as a variable (to be used when constructing the field tag) for each language.

let englishMessageToDisplay = "You've added a new scenario!"; 
let spanishMessageToDisplay = "Has añadido un nuevo escenario!";

Finally, we define a conditional for each language variable so that the proper field tag displays for each locale.

    if (spanish) 
        return skillContext.powers.andi.fieldTag.sendFieldTag(
            andiSkills.FieldTagTypes.Info,
            "new-scenario-added-skill", 
            1, 
            spanishMessageToDisplay,
            [],
            null,
            function(api, model, comparehash, custom) {
                return true;
            },
            null,
            null,
            null
        
        );

    if (english)
            
        return skillContext.powers.andi.fieldTag.sendFieldTag(
        andiSkills.FieldTagTypes.Info,
        "new-scenario-added-skill", 
        1, 
        englishMessageToDisplay,
        [],
        null,
        function(api, model, comparehash, custom) {
            return true;
        },
        null,
        null,
        null
    );

In total, for our example, the run.ts looks like the following: 

export function run(skillContext: andiSkills.ISkillContext) : Promise | andiSkills.ISkillActivity{

    let english = skillContext.getLocale() === "en-us";
    let spanish = skillContext.getLocale() === "es-es";
    let englishMessageToDisplay = "You've added a new scenario!"; 
    let spanishMessageToDisplay = "Has añadido un nuevo escenario!";

    if (spanish) 
        return skillContext.powers.andi.fieldTag.sendFieldTag(
            andiSkills.FieldTagTypes.Info,
            "new-scenario-added-skill", 
            1, 
            spanishMessageToDisplay,
            [],
            null,
            function(api, model, comparehash, custom) {
                return true;
            },
            null,
            null,
            null
        
        );

    if (english)
            
        return skillContext.powers.andi.fieldTag.sendFieldTag(
        andiSkills.FieldTagTypes.Info,
        "new-scenario-added-skill", 
        1, 
        englishMessageToDisplay,
        [],
        null,
        function(api, model, comparehash, custom) {
            return true;
        },
        null,
        null,
        null
    );
}

 

Once the skill has been deployed, the available languages will appear on the skill page in the Skills Manager. You will also see the language as an available option in the language filter on the Manage Skills Dashboard.

Was this article helpful?
0 out of 0 found this helpful