translation.Handle

Object Description

Encapsulates a Translation Collection for a locale.

Use translation.load(options) to create a translation.Handle object with translations for the specified Translation Collections and locales. Use translation.selectLocale(options) to create a translation.Handle object in the specified locale from an existing translation.Handle object.

The translation.Handle object is a hierarchical object, which means that each node in the object is either another translation.Handle object or a translation.Translator function. Translator functions combine strings with parameters. When you create a Translation Collection in the NetSuite UI, you can include parameter placeholders in your translation strings. The translator function injects the specified parameter values into the placeholders in the returned translation string.

Supported Script Types

Client and server scripts

For additional information, see SuiteScript 2.x Script Types.

Module

N/translation Module

Since

2019.1

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/translation Module Script Samples.

            // Add additional code
...
var localizedStrings = translation.load({
    collections: [{
        alias: 'myCollection',
        collection: 'custcollection_my_strings',
        keys: ['MY_TITLE', 'MY_MESSAGE']
    }]
});

let myMsg = message.create({
    title: localizedStrings.myCollection.MY_TITLE(),
    message: localizedStrings.myCollection.MY_MESSAGE(),
    type: message.Type.CONFIRMATION
});
...
// Add additional code 

          
            /**
 * @NApiVersion 2.1
 * @NScriptType clientscript
 */
define(['N/translation'], (translation) => {
    return {
        pageInit: function(context) {
            let handle = translation.load({
                collections: [
                    {alias: "phrases", collection: "CUSTCOLLECTION_PHRASES", keys: ["HELLO"]},
                        {alias: "specialstrings", collection: "CUSTCOLLECTION_SPECIALSTRINGS, keys: ["HELLO_1"]}
                ],
                locales: ["fr_FR", 'en_US']
            });

            // Logs hello in company default language - Hello (if default is English)
            console.log(handle.phrases.HELLO()); 
            let frenchHandle = translation.selectLocale({handle: result, locale: "fr_FR"});

            // Logs hello in french - Bonjour
            console.log(frenchHandle.phrases.HELLO());
                  //logs hello in french - Bonjour
        }
    };
...
// Add additional code 

          

Related Topics

General Notices