Langauge translation

Mansi roy
Tera Contributor

Hello All,

 

Can anyone please help me on the below requirement. I have written a business rule to set the set short description of the catalog item based on the few variables value.

 

In English version the short description is showing correctly but how to set this short description to japan langauge the japansese user will use this.

 

Can anyone please help how to achieve.

 

1 ACCEPTED SOLUTION

Hello @Mansi roy 

Here is the updated script:

var shdesc = '';
var roles = [];
var entitlements = [];
var role_mrvs = JSON.parse(current.variables.required_roles);
var entitlement_mrvs = JSON.parse(current.variables.required_entitlement);

if (role_mrvs != '') {
    for (var i = 0; i < role_mrvs.length; i++) {
        var gr_role = new GlideRecord('u_oim_roles_list_new');
        if (gr_role.get(role_mrvs[i].role)) {
            roles.push(gr_role.u_role_name);
        }
    }
    shdesc = gs.getMessage('For {0}: {1}: {2}', [
        current.variables.user_id.getDisplayValue(),
        current.variables.request_type.getDisplayValue(),
        roles.toString()
    ]);
}

if (entitlement_mrvs != '') {
    for (var j = 0; j < entitlement_mrvs.length; j++) {
        var gr_entitlement = new GlideRecord('u_oim_single_entitelments');
        if (gr_entitlement.get(entitlement_mrvs[j].entitlement_name)) {
            entitlements.push(gr_entitlement.u_entitlementname);
        }
    }
    shdesc = gs.getMessage('For {0}: {1}: {2}', [
        current.variables.user_id.getDisplayValue(),
        current.variables.request_type.getDisplayValue(),
        entitlements.toString()
    ]);
}

// Update the short description
current.short_description = shdesc;
current.update();
  • gs.getMessage() supports translation by replacing static strings with localized versions.
  • In this case, phrases like 'For {0}: {1}: {2}' will be translated if corresponding keys exist in the system.
  • Placeholders ({0}, {1}, {2}) are dynamically replaced with the provided values in the array.
  • Add translations for 'For {0}: {1}: {2}' into your system's Messages table (sys_ui_message), with keys and their corresponding translations (e.g., Japanese).

Adding Translation Keys

  1. Navigate to System UI > Messages.
  2. Create a new message entry:
    • Key: For {0}: {1}: {2}
    • Message (Japanese translation): 対象 {0}: {1}: {2}.
  3. Repeat for any other keys or phrases used.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

7 REPLIES 7

amitshishod
Tera Guru

Hello Buddy, Can you please paste your code here?

Hello @amitshishod ,

 

This short description i need to show in japanese language.

 

var shdesc = '';
    var roles = [];
    var entitlements = [];
    var role_mrvs = JSON.parse(current.variables.required_roles);
    var entitlement_mrvs = JSON.parse(current.variables.required_entitlement);
  if(role_mrvs != ''){
    for (var i = 0; i < role_mrvs.length; i++) {
        var gr_role = new GlideRecord('u_oim_roles_list_new');
        gr_role.get(role_mrvs[i].role);
        roles.push(gr_role.u_role_name);
    }
    shdesc = 'For' +' ' + current.variables.user_id.getDisplayValue() + ' '+ ':' + ' '+''+current.variables.request_type.getDisplayValue()+':'+' '  +  roles.toString();
  }
  if(entitlement_mrvs != ''){
    for (var j = 0; j < entitlement_mrvs.length; j++) {
        var gr_entitlement = new GlideRecord('u_oim_single_entitelments');
        gr_entitlement.get(entitlement_mrvs[j].entitlement_name);
        entitlements.push(gr_entitlement.u_entitlementname);
    }
    shdesc = 'For' + ' ' + current.variables.user_id.getDisplayValue() +'' +':'  + ''+current.variables.request_type.getDisplayValue()+':'+' ' +   entitlements.toString();
  }
        current.short_description = shdesc;
        current.update();
   
})(current, previous);

Hello @Mansi roy 

Here is the updated script:

var shdesc = '';
var roles = [];
var entitlements = [];
var role_mrvs = JSON.parse(current.variables.required_roles);
var entitlement_mrvs = JSON.parse(current.variables.required_entitlement);

if (role_mrvs != '') {
    for (var i = 0; i < role_mrvs.length; i++) {
        var gr_role = new GlideRecord('u_oim_roles_list_new');
        if (gr_role.get(role_mrvs[i].role)) {
            roles.push(gr_role.u_role_name);
        }
    }
    shdesc = gs.getMessage('For {0}: {1}: {2}', [
        current.variables.user_id.getDisplayValue(),
        current.variables.request_type.getDisplayValue(),
        roles.toString()
    ]);
}

if (entitlement_mrvs != '') {
    for (var j = 0; j < entitlement_mrvs.length; j++) {
        var gr_entitlement = new GlideRecord('u_oim_single_entitelments');
        if (gr_entitlement.get(entitlement_mrvs[j].entitlement_name)) {
            entitlements.push(gr_entitlement.u_entitlementname);
        }
    }
    shdesc = gs.getMessage('For {0}: {1}: {2}', [
        current.variables.user_id.getDisplayValue(),
        current.variables.request_type.getDisplayValue(),
        entitlements.toString()
    ]);
}

// Update the short description
current.short_description = shdesc;
current.update();
  • gs.getMessage() supports translation by replacing static strings with localized versions.
  • In this case, phrases like 'For {0}: {1}: {2}' will be translated if corresponding keys exist in the system.
  • Placeholders ({0}, {1}, {2}) are dynamically replaced with the provided values in the array.
  • Add translations for 'For {0}: {1}: {2}' into your system's Messages table (sys_ui_message), with keys and their corresponding translations (e.g., Japanese).

Adding Translation Keys

  1. Navigate to System UI > Messages.
  2. Create a new message entry:
    • Key: For {0}: {1}: {2}
    • Message (Japanese translation): 対象 {0}: {1}: {2}.
  3. Repeat for any other keys or phrases used.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

Thank u @Juhi Poddar ,

 

It works.