machineTranslation.translate(options)

Note:

The content in this help topic pertains to SuiteScript 2.1.

Method Description

Translates the provided documents into the specified language.

Unlike methods in the N/llm Module, this method supports unlimited translation requests and doesn't use a shared free usage pool. You also don't need to provide Oracle Cloud Infrastructure (OCI) credentials to get unlimited usage.

When passing documents (created using machineTranslation.createDocument(options)) to this method for translation, keep the following considerations in mind:

  • All document IDs must be unique.

  • The maximum length for a single document is 5,000 characters.

  • The maximum total length for all documents is 20,000 characters.

  • You can't pass an empty document (one where the Document.text property is empty).

  • If you pass a document that doesn't specify its source language (one where the Document.language property is null or undefined), the translation service detects the source language automatically.

Note:

For best translation results, each document should contain text in a single language only. The translation service supports documents that use multiple languages, but the accuracy and completeness of the resulting translation may vary.

As a best practice, you should create documents using machineTranslation.createDocument(options) and pass those documents to this method. However, you can also provide an ad hoc object that includes values for the id and text properties, as shown in the following example:

                    machineTranslation.translate({
    targetLanguage: machineTranslation.Language.GERMAN,
    documents: [
        {
            id: '1',
            text: 'How are you?'
        }
    ]
}); 

                  

Returns

machineTranslation.Response

Supported Script Types

Server scripts

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

Governance

100

Module

N/machineTranslation Module

Since

2025.1

Parameters

Parameter

Type

Required / Optional

Description

Since

options.documents

machineTranslation.Document[]

required

The documents to translate.

2025.1

options.targetLanguage

string

required

The language to translate the specified documents into.

Use values from the machineTranslation.Language enum to set the value of this parameter.

2025.1

options.timeout

number

optional

The timeout period to wait for a response from the translation service, in milliseconds.

The default value is 30,000 (30 seconds).

2025.1

Errors

Error Code

Thrown If

DOCUMENT_CANNOT_BE_EMPTY

One of the documents specified in the options.documents parameter is empty.

DOCUMENT_IDS_MUST_BE_UNIQUE

Two or more documents specified in the options.documents parameter have duplicate IDs.

DOCUMENT_TOO_LARGE

One of the documents specified in the options.documents parameter is longer than 5,000 characters.

INPUT_TOO_LARGE

The total length of all documents specified in the options.documents parameter is longer than 20,000 characters.

INVALID_LANGUAGE

One of the documents specified in the options.documents parameter uses a language that isn't part of the machineTranslation.Language enum.

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/machineTranslation Module Script Samples.

            // Add additional code
...

const myDocument1 = machineTranslation.createDocument({
    id: 'myDoc1',
    text: 'This is a document to be translated.'
});

const myDocument2 = machineTranslation.createDocument({
    id: 'myDoc2',
    text: 'This is another document to be translated.'
});

const translationResults = machineTranslation.translate({
    documents: [myDocument1, myDocument2],
    targetLanguage: machineTranslation.Language.CZECH
});

...
// Add additional code 

          

Related Topics

General Notices