translation.load(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Creates a translation.Handle object with translations for the specified Translation Collections and locales.

This method returns a translation.Handle object with translation strings organized by collection and ID. Every node in a translation.Handle object is either another translation.Handle object or a translation.Translator function.

You can load translation strings from multiple Translation Collections in a single call of translation.load(options). You must specify the keys of individual translation strings that you want to load. You cannot load all of the terms in a Translation Collection at one time. The translation.load(options) method can load a maximum of 1,000 translation strings, regardless of whether the strings are loaded from one collection or multiple collections.

When you load translation strings using translation.load(options), you can specify a list of valid locales for the strings. You can use these locales when you select a locale using translation.selectLocale(options). If you specify more than one locale when you call translation.load(options), the first specified locale in the list is used for the created translation.Handle object. If you want to use a different locale from the list, use translation.selectLocale(options), which returns a translation.Handle object in the specified locale. You must load a locale using translation.load(options) before you can select it using translation.selectLocale(options).

Returns

translation.Handle

Supported Script Types

Client and server scripts

For additional information, see SuiteScript 2.x Script Types.

Governance

10 units

Module

N/translation Module

Sibling Object Members

N/translation Module Members

Since

2019.1

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.collections

Object[]

required

A list of translation.Handle objects to load.

options.collections.alias

string

required

An alias to identify the collection.

This alias is used by the script to determine the collection to load.

options.collections.collection

string

required

The script ID of the collection to load.

options.collections.keys

string[]

required

A list of translation keys from the collection to load.

options.locales

string[]

optional

A list of locales to load the collection in.

Use the values in the translation.Locale enum to set this value.

Errors

Error Code

Thrown If

WRONG_PARAMETER_TYPE

One of the array parameters (options.collections, options.collections.keys, or options.locales) is not an array.

SSS_MISSING_REQD_ARGUMENT

A collection or key parameter is missing.

INVALID_TRANSLATION_KEY

The format of a specified key is invalid.

INVALID_TRANSLATION_COLLECTION

The format of a specified collection is invalid.

INVALID_LOCALE

The format of a specified locale is invalid.

INVALID_ALIAS

The format of a specified alias is invalid.

Syntax

Important:

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
...
let 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 

          

Related Topics

N/translation Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices