Access Translation Strings Using a Non-Default Locale
The following sample accesses translation strings using a locale other than the default locale. When you call translation.get(options) and do not specify a locale, the method uses the current user's session locale. You can use the options.locale
parameter to specify another locale. The translation.Locale enum lists all locales that are enabled for a company, and you can use these locales in translation.get(options)
. The translation.Locale
enum also includes two special values: CURRENT
and COMPANY_DEFAULT
. The CURRENT
value represents the current user’s locale, and the COMPANY_DEFAULT
value represents the default locale for the company.
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',
locale: translation.Locale.COMPANY_DEFAULT
})(),
message: translation.get({
collection: 'custcollection_my_strings',
key: 'MY_MESSAGE',
locale: translation.Locale.COMPANY_DEFAULT
})(),
type: message.Type.CONFIRMATION
});
// Show the message for 5 seconds
myMsg.show({
duration: 5000
});
});