N/machineTranslation Module Script Samples
The content in this help topic pertains to SuiteScript 2.1.
The following script samples demonstrate how to use the features of the N/machineTranslation module.
Translate a Document
The following sample creates a document and provides it to machineTranslation.translate(options) for translation. The sample specifies the source language of the document, but this step is optional. If you don't specify the source language of a document, the translation service detects the language automatically.
For instructions about how to run a SuiteScript 2.1 code snippet in the debugger, see On-Demand Debugging of SuiteScript 2.1 Scripts.
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.1
*/
require(['N/machineTranslation'],
function(mt) {
const myDocument = mt.createDocument({
id: 'myDoc',
text: 'Hello everyone! How are you today?',
language: mt.Language.ENGLISH
});
const translationResults = mt.translate({
documents: [myDocument],
targetLanguage: mt.Language.CZECH
});
// Work with the translated document
log.debug('Translated text', translationResults.results[0].text);
}
);