machineTranslation.createDocument(options)

Note:

The content in this help topic pertains to SuiteScript 2.1.

Method Description

Creates a document with the specified ID, source language, and text content.

A document represents text to translate using machineTranslation.translate(options). When you create a document for translation, you can specify the source language of the document. If you don't specify the source language, the translation service detects the 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.

When passing documents to machineTranslation.translate(options) 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 overall maximum 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.

Returns

machineTranslation.Document

Supported Script Types

Server scripts

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

Governance

None

Module

N/machineTranslation Module

Since

2025.1

Parameters

Parameter

Type

Required / Optional

Description

Since

options.id

string

required

The ID of the document.

2025.1

options.text

string

required

The text of the document.

2025.1

options.language

string

optional

The language of the document.

Use values from the machineTranslation.Language enum to set the value of this parameter. If you don't specify the document language, the translation service detects the language automatically when you pass the document to machineTranslation.translate(options).

2025.1

Errors

Error Code

Thrown If

INVALID_LANGUAGE

The options.language parameter uses a value 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