Access Translation Strings

The following sample accesses translation strings one at a time using translation.get(options). This method returns a translator function, which is subsequently called with any specified parameters. The translator function returns the string in the user's session locale by default.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

          /**
 * @NApiVersion 2.x
 */

require(['N/ui/message', 'N/translation'],
    function(message, translation) {

        // Create a message with translated strings
        var myMsg = message.create({
            title: translation.get({
                collection: 'custcollection_my_strings',
                key: 'MY_TITLE'
            })(),
            message: translation.get({
                collection: 'custcollection_my_strings',
                key: 'MY_MESSAGE'
            })(),
            type: message.Type.CONFIRMATION
        });

        // Show the message for 5 seconds
        myMsg.show({
            duration: 5000
        });
}); 

        

General Notices