Load Translation Strings by Key from Multiple Translation Collections
The following sample loads translation strings by key from multiple Translation Collections in a single call of translation.load(options). This method can load a maximum of 1,000 translation strings, regardless of whether the strings are loaded from one collection or multiple collections.
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) {
// Load two Translation Collections
var localizedStrings = translation.load({
collections: [{
alias: 'myCollection',
collection: 'custcollection_my_strings',
keys: ['MY_TITLE']
},{
alias: 'myOtherCollection',
collection: 'custcollection_other_strings',
keys: ['MY_OTHER_MESSAGE']
}]
});
// Create a message with translated strings
var myMsg = message.create({
title: localizedStrings.myCollection.MY_TITLE(),
message: localizedStrings.myOtherCollection.MY_OTHER_MESSAGE(),
type: message.Type.CONFIRMATION
});
// Show the message for 5 seconds
myMsg.show({
duration: 5000
});
});