Load Specific Translation Strings from a Collection

The following sample loads specific translation strings from a collection. The translation.load(options) method can load a maximum of 1,000 translation strings. If you need only a few of the translation strings in a collection, you can load only the strings you need instead of loading the entire collection.

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.1 Script Basics and SuiteScript 2.1 Script Types.

          /**
 * @NApiVersion 2.1
 */

require(['N/ui/message', 'N/translation'], (message, translation) => {
    const showTranslatedMessage = () => {
        // Load translation strings by key
        const localizedStrings = translation.load({
            collections: [{
                alias: 'myCollection',
                collection: 'custcollection_my_strings',
                keys: ['MY_TITLE', 'MY_MESSAGE']
            }]
        });

        // Create a message with translated strings
        const myMsg = message.create({
            title: localizedStrings.myCollection.MY_TITLE(),
            message: localizedStrings.myCollection.MY_MESSAGE(),
            type: message.Type.CONFIRMATION
        });

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

    return { showTranslatedMessage };
}); 

        

General Notices