Home Analyst Portal

Localization Custom Task

Vladimir_BudyakVladimir_Budyak Customer IT Monkey ✭

Dear colleagues!

How to localize the title of custom tasks?

If I use this code: app.custom.formTasks.add('mouse request to the service', location.NewcomerInformation, function (formObj, ViewModel) {...)} an error occurs: "SCRIPT5009:' localization ' is undefined
File: custom.js line: 45, column: 1"

Thank you!

Comments

  • Nicholas_VelichNicholas_Velich Cireson Consultant Ninja IT Monkey ✭✭✭✭
    Hi Vladimir,

    To localize the name of the task, you must put the code inside of a document.ready() call. For example:

    $(document).ready(function () {
             app.custom.formTasks.add('Incident', localization.LocalizationKey, function (formObj, viewModel) { 
                    // code goes here
            });
    });


    Thanks,
    Nick
  • Vladimir_BudyakVladimir_Budyak Customer IT Monkey ✭
    edited June 2016

    Great! It works! Thanks!!!

    Now I have a problem with a localization of html template (task form). :(

    The lable on the button: <%= localization.OK %>

    Tell me the solution, please.

  • Nicholas_VelichNicholas_Velich Cireson Consultant Ninja IT Monkey ✭✭✭✭
    Look for the section in your .js file that looks like this:


    require(["text!/CustomSpace/customtasks.nameofyourtemplate.html"], function (template) {
            cont = $(template);



    This is when the html template is loaded into your code. The cont variable is essentially a really long string at this point, and we have access to all the methods available for any other string. Your localizations can now be done by inserting the following snippet for each phrase you want to localize:



    cont.html(function(i, cont) {
            return cont.replace("LocalizationKey",localization.LocalizationKey);
    });



    In your HTML file itself, only the key would be specified. When the template is read in, it would be replaced based on the key using the code above. Does that make sense?
  • Vladimir_BudyakVladimir_Budyak Customer IT Monkey ✭

    Thank you very much! It works for me! It's very simple!


      cont.html(function(i, cont) {
       cont = cont.replace("localization.Cancel",localization.Cancel);
       cont = cont.replace("localization.OK",localization.OK);
       cont = cont.replace("localization.ContractStartDate",localization.ContractStartDate);
       cont = cont.replace("localization.ContractEndDate",localization.ContractEndDate);
       cont = cont.replace("localization.Location",localization.Location);
       cont = cont.replace("localization.Department",localization.Department);
       cont = cont.replace("localization.Position",localization.Position);
       cont = cont.replace("localization.Position",localization.Position);
       cont = cont.replace("localization.LastName",localization.LastName);
       cont = cont.replace("localization.LastName",localization.LastName);
       cont = cont.replace("localization.FirstName",localization.FirstName);
       cont = cont.replace("localization.FirstName",localization.FirstName);
       cont = cont.replace("localization.PatronymicName",localization.PatronymicName);
       cont = cont.replace("localization.PatronymicName",localization.PatronymicName);
       cont = cont.replace("localization.MonthOfBirth",localization.MonthOfBirth);
       cont = cont.replace("localization.DayOfBirth",localization.DayOfBirth);
       cont = cont.replace("localization.Room",localization.Room);
       cont = cont.replace("localization.EnterContractDate",localization.EnterContractDate);
       return cont;
      });

Sign In or Register to comment.