RWS Logo
Show / Hide Table of Contents

Cloud Operations

This section contains the Cloud specific setup and operations.

Building the CloudLanguageWeaverClient

Using default configuration:

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient()
        .build();
    // perform requests
} catch (e) {
    // handle errors;
}
Note

The default setup is the following:

  • Europe region
  • API credentials loaded from environment variables
  • Default retry mechanism (retry up to 3 times, with a delay of 5 seconds)

Using custom configuration - ClientConfiguration:

try {
    const retryConfiguration = new RetryConfiguration();
    retryConfiguration.attempts = 3;
    retryConfiguration.delay = 5000; // milliseconds
    const clientConfiguration = new ClientConfiguration();
    clientConfiguration.credentialsConfiguration = new CredentialsConfiguration("clientId", "clientSecret");
    clientConfiguration.retryConfiguration = retryConfiguration;

    let cloudLanguageWeaverClient = new CloudLanguageWeaverClient()
        .withConfigurations(clientConfiguration);
    cloudLanguageWeaverClient.region = Region.US;
    cloudLanguageWeaverClient = await cloudLanguageWeaverClient.build();
    // perform requests
} catch (e) {
    // handle errors
}

See API credentials and ClientConfiguration setup.
See API URL setup.

Using custom configuration - TokenConfiguration:

try {
    const token = new Token("accessToken", 86400, "tokenType", 1663409635000);
    const tokenConfiguration = new TokenConfiguration();
    tokenConfiguration.token = token;

    let cloudLanguageWeaverClient = new CloudLanguageWeaverClient()
        .withTokenConfigurations(tokenConfiguration);
    cloudLanguageWeaverClient.region = Region.US;
    cloudLanguageWeaverClient = await cloudLanguageWeaverClient.build();
    // perform requests
} catch (e) {
    // handle errors
}

See TokenConfiguration setup.

Get all Language Pairs

By using the getCloudLanguagePairs method from CloudLanguageWeaverClient, the list of available language pairs will be returned, corresponding to the given client identifier. These will be used for translation requests.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const languagePairsResult = await cloudLanguageWeaverClient.getCloudLanguagePairs();
    // handle result
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser

The CloudLanguagePairsResult object contains the following information:

Name Type Description
accountId number Account identifier
languagePairs CloudLanguagePair array Contains a list of CloudLanguagePair objects

The CloudLanguagePair object contains the following information:

Name Type Description
name string Language pair name
displayName string Language pair display name
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)

For more information about the API, access: Get all Language Pairs.

Get all Linguistic Options for a Language Pair

By using the getCloudLinguisticOptions method from CloudLanguageWeaverClient, the list of available linguistic options of a specific language pair will be returned, corresponding to the given client identifier. These will be used for translation requests.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const request = new CloudGetLinguisticOptionsRequest();
    request.sourceLanguageId = "chi";
    request.targetLanguageId = "eng";
    request.model = "generic";
    const linguisticOptionsResult = await cloudLanguageWeaverClient.getCloudLinguisticOptions(request);
    // handle result
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser

The CloudGetLinguisticOptionsRequest object contains the following information:

Name Type Mandatory Default value Description
sourceLanguageId string yes Three letters language code of the source language
targetLanguageId string yes Three letters language code of the target language
model string yes A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)

The CloudGetLinguisticOptionsRequest object can be obtained from an existing CloudLanguagePair object as well using the toCloudGetLinguisticOptionsRequest() method:

const cloudLinguisticOptionsRequest = cloudLanguagePair.toCloudGetLinguisticOptionsRequest();

The CloudLinguisticOptionsResult object contains the following information:

Name Type Description
linguisticOptions CloudLinguisticOption array List of linguistic options available for the requested language pair

The CloudLinguisticOption object contains the following information:

Name Type Description
id string Linguistic option identifier
name string Linguistic option name
systemDefault string System default linguistic option
accountDefault string Account default linguistic option. Field missing when there is no account default
values string array Available values for the current linguistic option

For more information about the API, access: Get all Linguistic Options for a language pair.

Get all Dictionaries

By using the getCloudDictionaries method from CloudLanguageWeaverClient, the list of available dictionaries will be returned, corresponding to the given client identifier. These can be used for translation requests.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const dictionariesResult = await cloudLanguageWeaverClient.getCloudDictionaries(1);
    // handle result
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser

The getCloudDictionaries method has the following parameters:

Name Type Mandatory Default Description
pageNumber number yes Number specifying the requested page number
pageSize number no 100 Number specifying the requested page size

The CloudDictionariesResult object contains the following information:

Name Type Description
accountId number Account identifier
dictionaries CloudDictionary array Contains a list of CloudDictionary objects
pageNumber number Number specifying the requested page number
pageSize number Number specifying the requested page size
totalCount number Total number of dictionaries in account

The CloudDictionary object contains the following information:

Name Type Description
accountId number Unique numeric identifier for the account associated to the dictionary
dictionaryId string Dictionary identifier
name string Name of the dictionary
description string Description for the dictionary
source string Three letters language code of the source language for the dictionary
target string Three letters language code of the target language for the dictionary
createdBy string The email of the user that created the dictionary
creationDate string Date when the dictionary was created
lastModifiedBy string The email of the user that last modified the dictionary
lastModifyDate string Date when the dictionary was last modified

For more information about the API, access: Get all Dictionaries.

Translations

Perform a Text Translation

The translateTextUsingCloudParams method from CloudLanguageWeaverClient, performs a text translation using a required CloudTranslateTextRequest object.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const translateTextRequest = new CloudTranslateTextRequest();
    translateTextRequest.sourceLanguageId = "eng";
    translateTextRequest.targetLanguageId = "fra";
    translateTextRequest.model = "generic";
    // provide list of dictionaries
    translateTextRequest.addDictionary("689f06cf-36ba-4903-a530-da1f7766f478");
    translateTextRequest.addDictionary("3d297ee3-0878-4ef7-9ee7-ca14b48e6956");
    translateTextRequest.addInput("The weather is wonderful today!");
    translateTextRequest.addInput("This is a new input that is part of an array translation.");
    translateTextRequest.inputFormat = Format.PLAIN;
    const translateTextResult = await cloudLanguageWeaverClient.translateTextUsingCloudParams(translateTextRequest);
    // handle result
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser

The CloudTranslateTextRequest object contains the following information:

Name Type Mandatory Default value Description
sourceLanguageId string yes Three letters language code of the source language or auto which signals that the source language should be auto detected
targetLanguageId string yes Three letters language code of the target language
model string no* See notes below A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
inputFormat Format no Format.PLAIN Format of input content. See Input Formats.
input string array yes Content to be translated. Input is added using the addInput method. This can be called multiple times in order to perform array translations.
dictionaries string array no empty A string array containing dictionary ids. Dictionaries are added using the addDictionary method. This can be called multiple times if multiple dictionaries need to be used in a translation.
linguisticOptions Map of strings no Map of strings containing pairs of linguistic option name and value. Values are case sensitive. You can only use the linguistic options that are available for that specific language pair. You can see what linguistic options are available for a language pair using this method call: Linguistic Options
Note

In order to use Linguistic Options feature you must enable it in your account

Text Input formats

Name Description
HTML HTML
PLAIN Plain text (UTF8)
XLINE Plain text, one sentence per line
TMX Translation Memory eXchange
XLIFF XML Localization Interchange File Format
BCM Proprietary format
XML Extensible Markup Language
SDLXML Treats every closing XML tag in the input as the end of a segment. The XML format in contrast does not make this assumption.
Note

sourceLanguageId, targetLanguageId, model - can be used in the following combinations:

  • sourceLanguageId=[languageName] and targetLanguageId=[languageName] and model=[identifier for the language pair] - when all three are used they uniquely identify a language pair e.g: Eng-Fra-generic
  • sourceLanguageId=auto, targetLanguageId=[languageName], model- will be ignored even if specified - A language pair that matches the detected source language and the specified target language will be automatically selected. The selected language pair will be the first one (in alphabetical order) available in your account that matches the selection. E.g. if the detected source language is eng and the target language is fra and your account has subscriptions to (EngFra-Generic, EngFra-Sports, EngFra-Sports123) the language pair selected will be EngFra-Generic.

The CloudTranslationTextResult object contains the following information:

Name Type Description
translation string array Array containing the translated content corresponding to the given input
requestId string Translation request identifier
inputFormat Format Format of input content
outputFormat Format Format of output content
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string String representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
translationStats object TranslationStatistics object

The TranslationStatistics object contains the following information:

Name Type Description
inputWordCount long Number of input words in the source translated
inputCharCount long Number of input characters in the source translated
inputByteCount long Number of input bytes in the source translated
translationWordCount long Number of output words in the source translated
translationCharCount long Number of output characters in the source translated
translationByteCount long Number of output bytes in the source translated

For more information about the API, access: Text Translations.

Perform a File Translation

The translateFileUsingCloudParams method from CloudLanguageWeaverClient, performs a file translation using a required CloudTranslateFileRequest object.

Backend JavaScript Environment

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const translateFileRequest = new CloudTranslateFileRequest();
    translateFileRequest.sourceLanguageId = "eng";
    translateFileRequest.targetLanguageId = "fra";
    translateFileRequest.model = "generic";
    translateFileRequest.inputFormat = Format.PLAIN;
    // provide list of dictionaries
    translateFileRequest.addDictionary("689f06cf-36ba-4903-a530-da1f7766f478");
    translateFileRequest.addDictionary("3d297ee3-0878-4ef7-9ee7-ca14b48e6956");
    // provide full path to the source file 
    translateFileRequest.input = path.resolve("/src/resources/input/input1.txt");
    // provide full path to the target directory
    translateFileRequest.outputDir = path.resolve("/src/resources/output");
    translateFileRequest.outputFile = "input1-translated.txt";
    await cloudLanguageWeaverClient.translateFileUsingCloudParams(translateFileRequest);
} catch (e) {
    // handle errors
}

See the complete sample on GitHub.

The CloudTranslateFileRequest object contains the following information:

Name Type Mandatory Default value Description
sourceLanguageId string yes Three letters language code of the source language or auto which signals that the source language should be auto detected
targetLanguageId string yes Three letters language code of the target language
model string no* See notes below A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
inputFormat Format no Format.PLAIN Format of input content. See Input Formats.
input string yes The path for the input file that needs to be translated
outputDir string no The path for the output directory that will contain the translated file. Also, the translated content will be returned as part of the TranslationFileResult as an IncomingMessage.
outputFile string no The name of the output file that will contain the translated content. If the outputFile is not provided, the filename is computed based on the input information like sourceLanguageId, targetLanguageId and model.
dictionaries string array no empty A string array containing dictionary ids. Dictionaries are added using the addDictionary method. This can be called multiple times if multiple dictionaries need to be used in a translation.
pdfConverter PdfConverter no PdfConverter.STANDARD An enum representing one of the three supported options for the pdf converter: SMART_SELECTION, ABBYY and STANDARD. ABBYY is used with better results for scanned PDFs. With SMART_SELECTION Language Weaver will choose the best pdf converter option for given input, the choice will be made between ABBYY and STANDARD.
linguisticOptions Map of strings no Map of strings containing pairs of linguistic option name and value. Values are case sensitive. You can only use the linguistic options that are available for that specific language pair. You can see what linguistic options are available for a language pair using this method call: Linguistic Options
Note

sourceLanguageId, targetLanguageId, model - can be used in the following combinations:

  • sourceLanguageId=[languageName] and targetLanguageId=[languageName] and model=[identifier for the language pair] - when all three are used they uniquely identify a language pair e.g: Eng-Fra-generic
  • sourceLanguageId=auto, targetLanguageId=[languageName], model- will be ignored even if specified - A language pair that matches the detected source language and the specified target language will be automatically selected. The selected language pair will be the first one (in alphabetical order) available in your account that matches the selection. E.g. if the detected source language is eng and the target language is fra and your account has subscriptions to (EngFra-Generic, EngFra-Sports, EngFra-Sports123) the language pair selected will be EngFra-Generic.
Note
  • For image input formats, output format is PLAIN text (.txt)
  • For EML and MSG input formats, output format is PLAIN text (.txt)
  • For PDF input format, output format is DOCX (.docx)
  • For all other input formats, output format is the same as the input format
Note

In order to use Linguistic Options feature you must enable it in your account

The CloudTranslationFileResult object contains the following information:

Name Type Description
fileContent IncomingMessage IncomingMessage representing the translated file content.
requestId string Translation request identifier
inputFormat Format Format of input content
outputFormat Format Format of output content
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string String representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
translationStats object TranslationStatistics object

The TranslationStatistics object contains the following information:

Name Type Description
inputWordCount long Number of input words in the source translated
inputCharCount long Number of input characters in the source translated
inputByteCount long Number of input bytes in the source translated
translationWordCount long Number of output words in the source translated
translationCharCount long Number of output characters in the source translated
translationByteCount long Number of output bytes in the source translated

For more information about the API, access: File Translations.

Browser JavaScript Environment

try {
    const clientConfiguration = new ClientConfiguration();
    clientConfiguration.credentialsConfiguration = new CredentialsConfiguration(clientId, clientSecret);
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient()
        .withConfigurations(clientConfiguration)
        .build();
    const translateFileRequest = new CloudTranslateFileRequest();
    translateFileRequest.sourceLanguageId = "eng";
    translateFileRequest.targetLanguageId = "fra";
    translateFileRequest.model = "generic";
    translateFileRequest.inputFormat = Format.PLAIN;
    // provide list of dictionaries
    translateFileRequest.addDictionary("689f06cf-36ba-4903-a530-da1f7766f478");
    translateFileRequest.addDictionary("3d297ee3-0878-4ef7-9ee7-ca14b48e6956");
    // provide a File object 
    translateFileRequest.input = file;
    const translateFileResult = await cloudLanguageWeaverClient.translateFileUsingCloudParams(translateFileRequest);
    // handle result
} catch (e) {
    // handle errors
}

See the complete sample on GitHub.

The CloudTranslateFileRequest object contains the following information:

Name Type Mandatory Default value Description
sourceLanguageId string yes Three letters language code of the source language or auto which signals that the source language should be auto detected
targetLanguageId string yes Three letters language code of the target language
model string no* See notes below A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
inputFormat Format no Format.PLAIN Format of input content. See Input Formats.
input File yes The file (File object) that needs to be translated
dictionaries string array no empty A string array containing dictionary ids. Dictionaries are added using the addDictionary method. This can be called multiple times if multiple dictionaries need to be used in a translation.
pdfConverter PdfConverter no PdfConverter.STANDARD An enum representing one of the three supported options for the pdf converter: SMART_SELECTION, ABBYY and STANDARD. ABBYY is used with better results for scanned PDFs. With SMART_SELECTION Language Weaver will choose the best pdf converter option for given input, the choice will be made between ABBYY and STANDARD.
linguisticOptions Map of strings no Map of strings containing pairs of linguistic option name and value. Values are case sensitive. You can only use the linguistic options that are available for that specific language pair. You can see what linguistic options are available for a language pair using this method call: Linguistic Options
Note

sourceLanguageId, targetLanguageId, model - can be used in the following combinations:

  • sourceLanguageId=[languageName] and targetLanguageId=[languageName] and model=[identifier for the language pair] - when all three are used they uniquely identify a language pair e.g: Eng-Fra-generic
  • sourceLanguageId=auto, targetLanguageId=[languageName], model- will be ignored even if specified - A language pair that matches the detected source language and the specified target language will be automatically selected. The selected language pair will be the first one (in alphabetical order) available in your account that matches the selection. E.g. if the detected source language is eng and the target language is fra and your account has subscriptions to (EngFra-Generic, EngFra-Sports, EngFra-Sports123) the language pair selected will be EngFra-Generic.
Note
  • For image input formats, output format is PLAIN text (.txt)
  • For EML and MSG input formats, output format is PLAIN text (.txt)
  • For PDF input format, output format is DOCX (.docx)
  • For all other input formats, output format is the same as the input format
Note

In order to use Linguistic Options feature you must enable it in your account

The CloudTranslationFileResult object contains the following information:

Name Type Description
fileContent Blob Blob representing the translated file content.
mimeType string A string representing the format of the translated file.
filename string A string representing the filename of the translated file. If the outputFile is not provided, the filename is computed based on the input information like sourceLanguageId, targetLanguageId and model.
requestId string Translation request identifier
inputFormat Format Format of input content
outputFormat Format Format of output content
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string String representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
translationStats object TranslationStatistics object

The TranslationStatistics object contains the following information:

Name Type Description
inputWordCount long Number of input words in the source translated
inputCharCount long Number of input characters in the source translated
inputByteCount long Number of input bytes in the source translated
translationWordCount long Number of output words in the source translated
translationCharCount long Number of output characters in the source translated
translationByteCount long Number of output bytes in the source translated

For more information about the API, access: File Translations.

Perform a Batch File Translation

The translateBatchFileUsingCloudParams method from CloudLanguageWeaverClient, performs a batch file translation using a required CloudTranslateBatchFileRequest object.

Backend JavaScript Environment

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const translateFileRequest = new CloudTranslateBatchFileRequest();
    translateFileRequest.sourceLanguageId = "eng";
    translateFileRequest.targetLanguageId = "fra";
    translateFileRequest.model = "generic";
    // provide list of dictionaries
    translateFileRequest.addDictionary("689f06cf-36ba-4903-a530-da1f7766f478");
    translateFileRequest.addDictionary("3d297ee3-0878-4ef7-9ee7-ca14b48e6956");
    // provide full path to the input and output folders 
    translateFileRequest.input = path.resolve("/src/resources/input");
    translateFileRequest.outputDir = path.resolve("/src/resources/output");
    await cloudLanguageWeaverClient.translateBatchFileUsingCloudParams(translateFileRequest);
} catch (e) {
    // handle errors
}

See the complete sample on GitHub.

The CloudTranslateBatchFileRequest object contains the following information:

Name Type Mandatory Default value Description
sourceLanguageId string yes Three letters language code of the source language or auto which signals that the source language should be auto detected
targetLanguageId string yes Three letters language code of the target language
model string no* See notes below A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
input string yes The path to the folder that contains the input files
outputDir string yes The path to the folder where the corresponding translated files will be added
dictionaries string array no empty A string array containing dictionary ids. Dictionaries are added using the addDictionary method. This can be called multiple times if multiple dictionaries need to be used in a translation.
pdfConverter PdfConverter no PdfConverter.STANDARD An enum representing one of the three supported options for the pdf converter: SMART_SELECTION, ABBYY and STANDARD. ABBYY is used with better results for scanned PDFs. With SMART_SELECTION Language Weaver will choose the best pdf converter option for given input, the choice will be made between ABBYY and STANDARD.
linguisticOptions Map of strings no Map of strings containing pairs of linguistic option name and value. Values are case sensitive. You can only use the linguistic options that are available for that specific language pair. You can see what linguistic options are available for a language pair using this method call: Linguistic Options
Note

sourceLanguageId, targetLanguageId, model - can be used in the following combinations:

  • sourceLanguageId=[languageName] and targetLanguageId=[languageName] and model=[identifier for the language pair] - when all three are used they uniquely identify a language pair e.g: Eng-Fra-generic
  • sourceLanguageId=auto, targetLanguageId=[languageName], model- will be ignored even if specified - A language pair that matches the detected source language and the specified target language will be automatically selected. The selected language pair will be the first one (in alphabetical order) available in your account that matches the selection. E.g. if the detected source language is eng and the target language is fra and your account has subscriptions to (EngFra-Generic, EngFra-Sports, EngFra-Sports123) the language pair selected will be EngFra-Generic.
Note
  • For image input formats, output format is PLAIN text (.txt)
  • For EML and MSG input formats, output format is PLAIN text (.txt)
  • For PDF input format, output format is DOCX (.docx)
  • For all other input formats, output format is the same as the input format
Note

In order to use Linguistic Options feature you must enable it in your account

The CloudTranslationBatchFileResult object contains the following information:

Name Type Description
translationFileResults CloudTranslationFileResult array A CloudTranslationFileResult array representing the translated files content. If an error occurs while translating a file, the error will not be returned or added to this array.

For more information about the API, access: File Translations.

Browser JavaScript Environment

try {
    const clientConfiguration = new ClientConfiguration();
    clientConfiguration.credentialsConfiguration = new CredentialsConfiguration(clientId, clientSecret);
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient()
        .withConfigurations(clientConfiguration)
        .build();
    const translateFileRequest = new CloudTranslateBatchFileRequest();
    translateFileRequest.sourceLanguageId = "eng";
    translateFileRequest.targetLanguageId = "fra";
    translateFileRequest.model = "generic";
    // provide list of dictionaries
    translateFileRequest.addDictionary("689f06cf-36ba-4903-a530-da1f7766f478");
    translateFileRequest.addDictionary("3d297ee3-0878-4ef7-9ee7-ca14b48e6956");
    // provide list of File objects
    translateFileRequest.input = [file1, file2];
    const translateFileResult = await cloudLanguageWeaverClient.translateBatchFileUsingCloudParams(translateFileRequest);
    // handle result
} catch (e) {
    // handle errors
}

See the complete sample on GitHub.

The CloudTranslateBatchFileRequest object contains the following information:

Name Type Mandatory Default value Description
sourceLanguageId string yes Three letters language code of the source language or auto which signals that the source language should be auto detected
targetLanguageId string yes Three letters language code of the target language
model string no* See notes below A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
input File array yes The File array that contains the input files
dictionaries string array no empty A string array containing dictionary ids. Dictionaries are added using the addDictionary method. This can be called multiple times if multiple dictionaries need to be used in a translation.
pdfConverter PdfConverter no PdfConverter.STANDARD An enum representing one of the three supported options for the pdf converter: SMART_SELECTION, ABBYY and STANDARD. ABBYY is used with better results for scanned PDFs. With SMART_SELECTION Language Weaver will choose the best pdf converter option for given input, the choice will be made between ABBYY and STANDARD.
linguisticOptions Map of strings no Map of strings containing pairs of linguistic option name and value. Values are case sensitive. You can only use the linguistic options that are available for that specific language pair. You can see what linguistic options are available for a language pair using this method call: Linguistic Options
Note

sourceLanguageId, targetLanguageId, model - can be used in the following combinations:

  • sourceLanguageId=[languageName] and targetLanguageId=[languageName] and model=[identifier for the language pair] - when all three are used they uniquely identify a language pair e.g: Eng-Fra-generic
  • sourceLanguageId=auto, targetLanguageId=[languageName], model- will be ignored even if specified - A language pair that matches the detected source language and the specified target language will be automatically selected. The selected language pair will be the first one (in alphabetical order) available in your account that matches the selection. E.g. if the detected source language is eng and the target language is fra and your account has subscriptions to (EngFra-Generic, EngFra-Sports, EngFra-Sports123) the language pair selected will be EngFra-Generic.
Note
  • For image input formats, output format is PLAIN text (.txt)
  • For EML and MSG input formats, output format is PLAIN text (.txt)
  • For PDF input format, output format is DOCX (.docx)
  • For all other input formats, output format is the same as the input format
Note

In order to use Linguistic Options feature you must enable it in your account

The TranslationBatchFileResult object contains the following information:

Name Type Description
translationFileResults CloudTranslationFileResult array A CloudTranslationFileResult array representing the translated files content. If an error occurs while translating a file, the error will not be returned or added to this array.

For more information about the API, access: File Translations.

Retrieve a File Translation

By using the retrieveCloudFileTranslation method from CloudLanguageWeaverClient, a file will be returned, corresponding to the given translation request identifier.

Backend JavaScript Environment

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const request = new CloudRetrieveFileRequest();
    request.requestId = "requestId";
    request.outputDir = path.resolve("resources/output");
    request.outputFile = "input1-translated.txt";
    const translateFileResult = await cloudLanguageWeaverClient.retrieveCloudFileTranslation(request);
    console.log(translateFileResult.fileContent);
} catch (e) {
    console.log(e);
}

See the complete sample on GitHub.

The CloudRetrieveFileRequest object contains the following information:

Name Type Mandatory Default value Description
requestId string yes Translation request identifier
outputDir string yes The path to the folder where the corresponding translated files will be added
outputFile string no The name of the output file that will contain the translated content. If the outputFile is not provided, the filename is computed based on the input information like sourceLanguageId, targetLanguageId and model.
Note
  • For image input formats, output format is PLAIN text (.txt)
  • For EML and MSG input formats, output format is PLAIN text (.txt)
  • For PDF input format, output format is DOCX (.docx)
  • For all other input formats, output format is the same as the input format

The CloudTranslationFileResult object contains the following information:

Name Type Description
fileContent IncomingMessage IncomingMessage representing the translated file content.
requestId string Translation request identifier
inputFormat Format Format of input content
outputFormat Format Format of output content
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string String representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
translationStats object TranslationStatistics object

The TranslationStatistics object contains the following information:

Name Type Description
inputWordCount long Number of input words in the source translated
inputCharCount long Number of input characters in the source translated
inputByteCount long Number of input bytes in the source translated
translationWordCount long Number of output words in the source translated
translationCharCount long Number of output characters in the source translated
translationByteCount long Number of output bytes in the source translated

For more information about the API, access: File Translations.

Browser JavaScript Environment

try {
    const clientConfiguration = new ClientConfiguration();
    clientConfiguration.credentialsConfiguration = new CredentialsConfiguration(clientId, clientSecret);
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient()
        .withConfigurations(clientConfiguration)
        .build();
    const request = new CloudRetrieveFileRequest();
    request.requestId = "requestId";
    const translateFileResult = await cloudLanguageWeaverClient.retrieveCloudFileTranslation(request);
    console.log(translateFileResult.fileContent);
} catch (e) {
    console.log(e);
}

See the complete sample on GitHub.

The CloudRetrieveFileRequest object contains the following information:

Name Type Mandatory Default value Description
requestId string yes Translation request identifier
Note
  • For image input formats, output format is PLAIN text (.txt)
  • For EML and MSG input formats, output format is PLAIN text (.txt)
  • For PDF input format, output format is DOCX (.docx)
  • For all other input formats, output format is the same as the input format

The CloudTranslationFileResult object contains the following information:

Name Type Description
fileContent Blob Blob representing the translated file content.
mimeType string A string representing the format of the translated file.
filename string A string representing the filename of the translated file. If the outputFile is not provided, the filename is computed based on the input information like sourceLanguageId, targetLanguageId and model.
requestId string Translation request identifier
inputFormat Format Format of input content
outputFormat Format Format of output content
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string String representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
translationStats object TranslationStatistics object

The TranslationStatistics object contains the following information:

Name Type Description
inputWordCount long Number of input words in the source translated
inputCharCount long Number of input characters in the source translated
inputByteCount long Number of input bytes in the source translated
translationWordCount long Number of output words in the source translated
translationCharCount long Number of output characters in the source translated
translationByteCount long Number of output bytes in the source translated

For more information about the API, access: File Translations.

Content Insights

Create Content Insights

The getCloudContentInsights method from CloudLanguageWeaverClient creates Content Insights using a required CloudFileContentInsightsRequest object.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const cloudFileContentInsightsRequest = new CloudFileContentInsightsRequest();
    cloudFileContentInsightsRequest.sourceLanguage = "eng";
    cloudFileContentInsightsRequest.files = path.resolve("resources/input/input1.txt");

    const contentInsightsResult = await cloudLanguageWeaverClient.getCloudContentInsights(cloudFileContentInsightsRequest);
    console.log(contentInsightsResult);
} catch (e) {
    console.log(e);
}

See the complete samples on GitHub:

  • backend
  • browser

The CloudFileContentInsightsRequest object contains the following information:

Name Type Mandatory Default
value
Description
sourceLanguage string yes Three letters language code of the source language
files string/File/File array yes The full path of the source files/file for backend implementation and File/array of File for browser implementation

The CloudContentInsightsResult object contains the following information:

Name Type Description
contentInsightsId string The id of the content insights request. This has to be used for the subsequent calls
sourceLanguage string Three letters language code of the source language
stats CloudContentInsightsStatistics Object containing the number of input words in the source files and the number of input characters in the source files
summarization CloudSummarization Object containing the sentences from the input files that were selected as part of the summary

The CloudContentInsightsStatistics object contains the following information:

Name Type Description
inputWordCount number Number of input words in the source translated
inputCharCount number Number of input characters in the source translated

The CloudSummarization object contains the following information:

Name Type Description
segments CloudSegment array The array with the sentences from the input files that were selected as part of the summary

The CloudSegment object contains the following information:

Name Type Description
text string A sentence from the input files that was selected to be part of the summary
lineNumber number The line number of the sentence in the input file
score number A score between 0 and 1. The higher the score, the more representative the sentence is for the summary

For more information about the API, access: Content Insights.

Create Content Insights For Existing Translations

The getCloudContentInsightsForTranslations method from CloudLanguageWeaverClient performs content insights for existing translations using a required translationIds list.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const cloudContentInsightsRequest = new CloudContentInsightsRequest();
    cloudContentInsightsRequest.addTranslationId("translationId");

    const contentInsightsResult = await cloudLanguageWeaverClient.getCloudContentInsightsForTranslations(cloudContentInsightsRequest);
    console.log(contentInsightsResult);
} catch (e) {
    console.log(e);
}

See the complete samples on GitHub:

  • backend
  • browser
Note

When you perform content insights for existing translation, you need to disable "Content deletion" and enable "Content Insights" from your account settings

The CloudContentInsightsRequest object contains the following information:

Name Type Mandatory Default value Description
translationIds string array yes A string array containing translation ids

The CloudContentInsightsResult object contains the following information:

Name Type Description
contentInsightsId string The id of the content insights request. This has to be used for the subsequent calls
sourceLanguage string Three letters language code of the source language
stats CloudContentInsightsStatistics Object containing the number of input words in the source files and the number of input characters in the source files
summarization CloudSummarization Object containing the sentences from the input files that were selected as part of the summary

The CloudContentInsightsStatistics object contains the following information:

Name Type Description
inputWordCount number Number of input words in the source translated
inputCharCount number Number of input characters in the source translated

The CloudSummarization object contains the following information:

Name Type Description
segments CloudSegment array The array with the sentences from the input files that were selected as part of the summary

The CloudSegment object contains the following information:

Name Type Description
text string A sentence from the input files that was selected to be part of the summary
lineNumber number The line number of the sentence in the input file
score number A score between 0 and 1. The higher the score, the more representative the sentence is for the summary

For more information about the API, access: Content Insights For Existing Translations .

Feedback Management

Get All Feedback

By using the getCloudFeedback method from CloudLanguageWeaverClient, the list of available feedback will be returned, corresponding to the given client identifier.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const sortRequest = new CloudFeedbackSortRequest();
    sortRequest.criteria = CloudFeedbackSortCriteria.DATE;
    sortRequest.order = Order.DESCENDING;
    const filterRequest = new CloudFilterFeedbackRequest();
    filterRequest.feedbackId = "e8b01170-1bc4-4d61-89f7-fc2f65733442";
    filterRequest.startDate = "10-04-2022";
    filterRequest.endDate = "10-24-2022";
    filterRequest.approvalStatus = ApprovalStatus.APPROVED;
    filterRequest.user = "123";
    filterRequest.sortRequest = sortRequest;
    const feedbackResult = await cloudLanguageWeaverClient.getCloudFeedback(1, 50, filterRequest);
    // handle result
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser


The getCloudFeedback method has the following parameters:

Name Type Mandatory Default Description
pageNumber number yes Number specifying the requested page number
pageSize number no 100 Number specifying the requested page size
filterRequest CloudFilterFeedbackRequest no String specifying the criteria by which the returned feedback to be filtered

The CloudFilterFeedbackRequest object contains the following information:

Name Type Mandatory Default Description
startDate string yes The start date for the filtered feedback
endDate string yes The end date for the filtered feedback
user string no The id of the user who created the feedback
feedbackId string no Feedback identifier
approvalStatus ApprovalStatus no The approval status of the feedback (APPROVED, REJECTED, PENDING)
sortRequest CloudFeedbackSortRequest no Object specifying the criteria by which the returned feedback to be sorted

The CloudFeedbackSortRequest object contains the following information:

Name Type Mandatory Default Description
criteria CloudFeedbackSortCriteria yes DATE or LP
order Order yes ASCENDING ASCENDING or DESCENDING

The CloudFeedbackListResult object contains the following information:

Name Type Description
feedbackList CloudFeedbackResult array Contains a list of CloudFeedbackResult objects
pageNumber number Number specifying the requested page number
pageSize number Number specifying the requested page size
totalCount number Total number of feedback in account

The CloudFeedbackResult object contains the following information:

Name Type Description
feedbackId string Feedback identifier
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
sourceText string Text provided to be translated
targetText string Translation provided by machine translation
suggestedTranslation string Expected translation
numberOfSegments number Positive number which represents number of segments for translation (default value is 1)
qualityEstimationMT QualityEstimation The quality estimation provided by machine translation (GOOD, ADEQUATE, POOR)
qualityEstimation QualityEstimation Expected quality estimation (GOOD, ADEQUATE, POOR)
approvalState ApprovalStatus The approval status of the feedback (APPROVED, REJECTED, PENDING)
feedbackAuditData CloudAuditData An object representing the details about the lifecycle of the feedback
approvalAuditData CloudAuditData An object representing the details about the lifecycle of the feedback approval status

The CloudAuditData object contains the following information:

Name Type Description
createdByAccountId string The id of the account which created the feedback
createdByUserId string The id of the user who created the feedback
createdByClientId string The client id which created the feedback
createdByUserEmail string The email of the user who created the feedback
creationDate string Creation date of the feedback
lastModifiedByAccountId string The id of the account which last modified the feedback
lastModifiedByUserId string The id of the user who last modified the feedback
lastModifiedByClientId string The client id which last modified the feedback
lastModifiedByUserEmail string The email of the user who last modified the feedback
lastModifyDate string The date when the feedback was last modified

For more information about the API, access: Filter Feedback.

Create Feedback

The createCloudFeedback method from CloudLanguageWeaverClient can be used to add a new translation feedback.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const createRequest = new CloudCreateFeedbackRequest();
    createRequest.sourceLanguageId = "eng";
    createRequest.targetLanguageId = "fra";
    createRequest.model = "generic";
    createRequest.sourceText = "This is a sample input text.";
    createRequest.targetText = "C'est un exemple de texte d'entrée.";
    createRequest.suggestedTranslation = "Ceci est un exemple de texte d'entrée.";
    createRequest.numberOfSegments = 1;
    createRequest.qualityEstimationMT = QualityEstimation.GOOD;
    createRequest.qualityEstimation = QualityEstimation.ADEQUATE;
    const feedbackResult = await cloudLanguageWeaverClient.createCloudFeedback(createRequest);
    // handle result
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser


The CloudCreateFeedbackRequest object contains the following information:

Name Type Mandatory Default Description
sourceLanguageId string yes Three letters language code of the source language
targetLanguageId string yes Three letters language code of the target language
model string yes A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
sourceText string yes Text provided to be translated
targetText string yes Translation provided by machine translation
suggestedTranslation string yes Expected translation
numberOfSegments number no 1 Positive number which represents number of segments for translation
qualityEstimationMT QualityEstimation no The quality estimation provided by machine translation (GOOD, ADEQUATE, POOR)
qualityEstimation QualityEstimation no Expected quality estimation (GOOD, ADEQUATE, POOR)

The CloudFeedbackResult object contains the following information:

Name Type Description
feedbackId string Feedback identifier
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
sourceText string Text provided to be translated
targetText string Translation provided by machine translation
suggestedTranslation string Expected translation
numberOfSegments number Positive number which represents number of segments for translation (default value is 1)
qualityEstimationMT QualityEstimation The quality estimation provided by machine translation (GOOD, ADEQUATE, POOR)
qualityEstimation QualityEstimation Expected quality estimation (GOOD, ADEQUATE, POOR)
approvalState ApprovalStatus The approval status of the feedback (APPROVED, REJECTED, PENDING)
feedbackAuditData CloudAuditData An object representing the details about the lifecycle of the feedback
approvalAuditData CloudAuditData An object representing the details about the lifecycle of the feedback approval status

The CloudAuditData object contains the following information:

Name Type Description
createdByAccountId string The id of the account which created the feedback
createdByUserId string The id of the user who created the feedback
createdByClientId string The client id which created the feedback
createdByUserEmail string The email of the user who created the feedback
creationDate string Creation date of the feedback
lastModifiedByAccountId string The id of the account which last modified the feedback
lastModifiedByUserId string The id of the user who last modified the feedback
lastModifiedByClientId string The client id which last modified the feedback
lastModifiedByUserEmail string The email of the user who last modified the feedback
lastModifyDate string The date when the feedback was last modified

For more information about the API, access: Create Feedback.

Update Feedback

The updateCloudFeedback method from CloudLanguageWeaverClient can be used to update an existing translation feedback.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const updateRequest = new CloudUpdateFeedbackRequest();
    updateRequest.feedbackId = "e8b01170-1bc4-4d61-89f7-fc2f65733442";
    updateRequest.suggestedTranslation = "Ceci est un exemple de texte d'entrée.";
    updateRequest.qualityEstimation = QualityEstimation.GOOD;
    const feedbackResult = await cloudLanguageWeaverClient.updateCloudFeedback(updateRequest);
    // handle result
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser


The CloudUpdateFeedbackRequest object contains the following information:

Name Type Mandatory Default Description
feedbackId string yes Feedback identifier
suggestedTranslation string no Expected translation
qualityEstimation QualityEstimation no Expected quality estimation (GOOD, ADEQUATE, POOR)

The CloudFeedbackResult object contains the following information:

Name Type Description
feedbackId string Feedback identifier
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
sourceText string Text provided to be translated
targetText string Translation provided by machine translation
suggestedTranslation string Expected translation
numberOfSegments number Positive number which represents number of segments for translation (default value is 1)
qualityEstimationMT QualityEstimation The quality estimation provided by machine translation (GOOD, ADEQUATE, POOR)
qualityEstimation QualityEstimation Expected quality estimation (GOOD, ADEQUATE, POOR)
approvalState ApprovalStatus The approval status of the feedback (APPROVED, REJECTED, PENDING)
feedbackAuditData CloudAuditData An object representing the details about the lifecycle of the feedback
approvalAuditData CloudAuditData An object representing the details about the lifecycle of the feedback approval status

The CloudAuditData object contains the following information:

Name Type Description
createdByAccountId string The id of the account which created the feedback
createdByUserId string The id of the user who created the feedback
createdByClientId string The client id which created the feedback
createdByUserEmail string The email of the user who created the feedback
creationDate string Creation date of the feedback
lastModifiedByAccountId string The id of the account which last modified the feedback
lastModifiedByUserId string The id of the user who last modified the feedback
lastModifiedByClientId string The client id which last modified the feedback
lastModifiedByUserEmail string The email of the user who last modified the feedback
lastModifyDate string The date when the feedback was last modified

For more information about the API, access: Update Feedback.

Update Feedback Approval Status

The updateCloudFeedbackApproval method from CloudLanguageWeaverClient can be used to update the approval status of an existing translation feedback.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const updateRequest = new CloudUpdateFeedbackApprovalRequest();
    updateRequest.feedbackId = "e8b01170-1bc4-4d61-89f7-fc2f65733442";
    updateRequest.approvalStatus = ApprovalStatus.APPROVED;
    const feedbackResult = await cloudLanguageWeaverClient.updateCloudFeedbackApproval(updateRequest);
    // handle result
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser


The CloudUpdateFeedbackApprovalRequest object contains the following information:

Name Type Mandatory Default Description
feedbackId string yes Feedback identifier
approvalStatus ApprovalStatus yes The approval status of the feedback (APPROVED, REJECTED, PENDING)

The CloudFeedbackResult object contains the following information:

Name Type Description
feedbackId string Feedback identifier
sourceLanguageId string Three letters language code of the source language
targetLanguageId string Three letters language code of the target language
model string A string representing a unique identifier for the language pair combination sourceLanguageId-targetLanguageId-model. (e.g. generic)
sourceText string Text provided to be translated
targetText string Translation provided by machine translation
suggestedTranslation string Expected translation
numberOfSegments number Positive number which represents number of segments for translation (default value is 1)
qualityEstimationMT QualityEstimation The quality estimation provided by machine translation (GOOD, ADEQUATE, POOR)
qualityEstimation QualityEstimation Expected quality estimation (GOOD, ADEQUATE, POOR)
approvalState ApprovalStatus The approval status of the feedback (APPROVED, REJECTED, PENDING)
feedbackAuditData CloudAuditData An object representing the details about the lifecycle of the feedback
approvalAuditData CloudAuditData An object representing the details about the lifecycle of the feedback approval status

The CloudAuditData object contains the following information:

Name Type Description
createdByAccountId string The id of the account which created the feedback
createdByUserId string The id of the user who created the feedback
createdByClientId string The client id which created the feedback
createdByUserEmail string The email of the user who created the feedback
creationDate string Creation date of the feedback
lastModifiedByAccountId string The id of the account which last modified the feedback
lastModifiedByUserId string The id of the user who last modified the feedback
lastModifiedByClientId string The client id which last modified the feedback
lastModifiedByUserEmail string The email of the user who last modified the feedback
lastModifyDate string The date when the feedback was last modified

For more information about the API, access: Update Feedback Approval Status.

Delete Feedback

The deleteCloudFeedback method from CloudLanguageWeaverClient can be used to delete an existing translation feedback.

try {
    const cloudLanguageWeaverClient = await new CloudLanguageWeaverClient().build();
    const deleteRequest = new CloudDeleteFeedbackRequest();
    deleteRequest.feedbackId = "e8b01170-1bc4-4d61-89f7-fc2f65733442";
    await cloudLanguageWeaverClient.deleteCloudFeedback(deleteRequest);
} catch (e) {
    // handle errors
}

See the complete samples on GitHub:

  • backend
  • browser


The CloudDeleteFeedbackRequest object contains the following information:

Name Type Mandatory Default Description
feedbackId string yes Feedback identifier

For more information about the API, access: Delete Feedback.

In this page
Back to top