PowerForms - label localization

09/03/2015 17:10

JavaScript for label localization in PowerForms.

- Insert following code to 'Load Completed' section in Scripts part in Options tab, or include external .js file with functions.

- Use label value in form: Moj nadpis|My Title (for sk-SK|en-US version).

- Add SetLabel method call to this script for each label you want to localize

- If you want to change the default language or add more languages, update switch command

- You can use SetLabel method also for button text

 

Note: In case you use external javascript file, make sure your functions contains also form parameter and also use this parameter in function call - if it's needed of course:)

Example:

function in external js file

function SetLabel(form, language, controlName) {
    var label = form.GetControl(controlName);
    var labelValue = label.GetValue();

    var translated = GetLocalizedText(language, labelValue);

    label.SetValue(translated);
}

Call

var userLang = navigator.language || navigator.userLanguage;

SetLabel(form, userLang, "lbl_Title");

 

Code direct in form

//code for localization, use switch order to enter label value (e.g. Stitok'Tag means sk-Sk'en-US), sk is default

var userLang = navigator.language || navigator.userLanguage;
SetLabel(userLang, "c_lblTest");

 

function SetLabel(language, controlName) {
    var label = form.GetControl(controlName);
    var labelValue = label.GetValue();

    var translated = GetLocalizedText(language, labelValue);

    label.SetValue(translated);
}


function GetLocalizedText(language, labelValue) {

    var translations = labelValue.split('|');
    var translated;

    if (translations.length == 1) {
        translated = translations[0];
    }
    else {

        switch (language) {
            case "sk-SK":
                translated = translations[0];
                break;
            case "en-US":
                translated = translations[1];
                break;
            default:
                translated = translations[0];
        }
    }
    return translated;
}