translation.Handle
Object Description |
Encapsulates a Translation Collection for a locale. Use translation.load(options) to create a The |
Supported Script Types |
Client and server scripts For additional information, see SuiteScript 2.x Script Types. |
Module |
|
Since |
2019.1 |
Syntax
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