Common Operations
The common operations are performed using the default setup:
- Cloud product using the Europe region
- API credentials loaded from environment variables
- Default retry mechanism (retry up to 3 times, with a delay of 5 seconds)
Note
In order to switch the product to Edge, this must be set either on the ClientConfiguration/TokenConfiguration or by using an environment variable as described in Switch between Products section.
Get all Language Pairs
By using the getLanguagePairs method from LanguageWeaverClient, the list of available language pairs will be returned, corresponding to the given client identifier. These will be used for translation requests.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const languagePairsResult = await lwClient.getLanguagePairs();
// handle result
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The LanguagePairsResult object contains the following information:
Name | Type | Description |
---|---|---|
languagePairs |
LanguagePair array | Contains a list of LanguagePair objects |
The LanguagePair object contains the following information:
Name | Type | Description |
---|---|---|
name |
string | Language pair 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 getLinguisticOptions method from LanguageWeaverClient, 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 lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const request = new GetLinguisticOptionsRequest();
request.sourceLanguageId = "chi";
request.targetLanguageId = "eng";
request.model = "generic";
const linguisticOptionsResult = await lwClient.getLinguisticOptions(request);
// handle result
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The GetLinguisticOptionsRequest 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 GetLinguisticOptionsRequest object can be obtained from an existing LanguagePair object as well using the toGetLinguisticOptionsRequest() method:
const linguisticOptionsRequest = languagePair.toGetLinguisticOptionsRequest();
The LinguisticOptionsResult object contains the following information:
Name | Type | Description |
---|---|---|
linguisticOptions |
LinguisticOption array | List of linguistic options available for the requested language pair |
The LinguisticOption object contains the following information:
Name | Type | Description |
---|---|---|
id |
string | Linguistic option identifier |
systemDefault |
string | System default linguistic option |
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 getDictionaries method from LanguageWeaverClient, the list of available dictionaries will be returned, corresponding to the given client identifier. These can be used for translation requests.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const dictionariesResult = await lwClient.getDictionaries(1);
// handle result
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The getDictionaries 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 DictionariesResult object contains the following information:
Name | Type | Description |
---|---|---|
dictionaries |
Dictionary array | Contains a list of Dictionary 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 Dictionary object contains the following information:
Name | Type | Description |
---|---|---|
id |
string | Dictionary identifier |
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 |
For more information about the API, access: Get all Dictionaries.
Translations
Perform a Text Translation
The translateText method from LanguageWeaverClient, performs a text translation using a required TranslateTextRequest object.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const translateTextRequest = new TranslateTextRequest();
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.inputFormat = Format.PLAIN;
const translateTextResult = await lwClient.translateText(translateTextRequest);
// handle result
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The TranslateTextRequest 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
If Edge product is selected, when performing a translation using sourceLanguageId, targetLanguageId and model combination, the selected language pair will be the first matching the combination.
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 TranslateTextResult object contains the following information:
Name | Type | Description |
---|---|---|
translation |
string | Translated content |
For more information about the API, access: Text Translations.
Perform a File Translation
The translateFile method from LanguageWeaverClient, performs a file translation using a required TranslateFileRequest object.
Backend JavaScript Environment
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const translateFileRequest = new TranslateFileRequest();
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");
translateFileRequest.inputFormat = Format.PLAIN;
// 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 lwClient.translateFile(translateFileRequest);
} catch (e) {
// handle errors
}
See the complete sample on GitHub.
The TranslateFileRequest 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 | empty* | 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
If Edge product is selected, when performing a translation using sourceLanguageId, targetLanguageId and model combination, the selected language pair will be the first matching the combination.
Note
Pdf Converter default value:
- Cloud will automatically use
STANDARD
- Edge (licensed with ABBYY) will automatically use
ABBYY
when the source file is a scanned PDF, or if the source language is right-to-left (RTL) script or one of the following: Chinese (Simplified and Traditional), Japanese, Korean, Vietnamese, Thai, Hindi or Burmese; Edge will use standard conversion for all other source languages when the source file is not a scanned PDF
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 TranslationFileResult object contains the following information:
Name | Type | Description |
---|---|---|
fileContent |
IncomingMessage | IncomingMessage representing the translated file content. This is populated all the time even if the translated content is stored in an output file on the disk, based on the outputDir and outputFile values. |
requestId |
string | Translation request identifier |
For more information about the API, access: File Translations.
Browser JavaScript Environment
In browser, the input must be a File object.
try {
const clientConfiguration = new ClientConfiguration();
clientConfiguration.credentialsConfiguration = new CredentialsConfiguration(clientId, clientSecret);
const lwClient = await SdkFactory.getLanguageWeaverClient(clientConfiguration);
const translateFileRequest = new TranslateFileRequest();
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");
translateFileRequest.inputFormat = Format.PLAIN;
// provide a File object
translateFileRequest.input = file;
const translateFileResult = await lwClient.translateFile(translateFileRequest);
// handle result
} catch (e) {
// handle errors
}
See the complete sample on GitHub.
The TranslateFileRequest 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 | empty* | 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
If Edge product is selected, when performing a translation using sourceLanguageId, targetLanguageId and model combination, the selected language pair will be the first matching the combination.
Note
Pdf Converter default value:
- Cloud will automatically use
STANDARD
- Edge (licensed with ABBYY) will automatically use
ABBYY
when the source file is a scanned PDF, or if the source language is right-to-left (RTL) script or one of the following: Chinese (Simplified and Traditional), Japanese, Korean, Vietnamese, Thai, Hindi or Burmese; Edge will use standard conversion for all other source languages when the source file is not a scanned PDF
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 TranslationFileResult 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. |
For more information about the API, access: File Translations.
Perform a Batch File Translation
The translateBatchFile method from LanguageWeaverClient, performs a batch file translation using a required TranslateBatchFileRequest object.
Backend JavaScript Environment
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const translateFileRequest = new TranslateBatchFileRequest();
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 lwClient.translateBatchFile(translateFileRequest);
} catch (e) {
// handle errors
}
See the complete sample on GitHub.
The TranslateBatchFileRequest 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 | empty* | 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
If Edge product is selected, when performing a translation using sourceLanguageId, targetLanguageId and model combination, the selected language pair will be the first matching the combination.
Note
Pdf Converter default value:
- Cloud will automatically use
STANDARD
- Edge (licensed with ABBYY) will automatically use
ABBYY
when the source file is a scanned PDF, or if the source language is right-to-left (RTL) script or one of the following: Chinese (Simplified and Traditional), Japanese, Korean, Vietnamese, Thai, Hindi or Burmese; Edge will use standard conversion for all other source languages when the source file is not a scanned PDF
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 |
TranslationFileResult array | A TranslationFileResult 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 lwClient = await SdkFactory.getLanguageWeaverClient(clientConfiguration);
const translateFileRequest = new TranslateBatchFileRequest();
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 lwClient.translateBatchFile(translateFileRequest);
// handle result
} catch (e) {
// handle errors
}
See the complete sample on GitHub.
The TranslateBatchFileRequest 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 | empty* | 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
If Edge product is selected, when performing a translation using sourceLanguageId, targetLanguageId and model combination, the selected language pair will be the first matching the combination.
Note
Pdf Converter default value:
- Cloud will automatically use
STANDARD
- Edge (licensed with ABBYY) will automatically use
ABBYY
when the source file is a scanned PDF, or if the source language is right-to-left (RTL) script or one of the following: Chinese (Simplified and Traditional), Japanese, Korean, Vietnamese, Thai, Hindi or Burmese; Edge will use standard conversion for all other source languages when the source file is not a scanned PDF
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 |
TranslationFileResult array | A TranslationFileResult 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 retrieveFileTranslation method from LanguageWeaverClient, a file will be returned, corresponding to the given translation request identifier.
Backend JavaScript Environment
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const request = new RetrieveFileRequest();
request.requestId = "requestId";
request.outputDir = path.resolve("resources/output");
request.outputFile = "input1-translated.txt";
const translateFileResult = await lwClient.retrieveFileTranslation(request);
console.log(translateFileResult.fileContent);
} catch (e) {
console.log(e);
}
See the complete sample on GitHub.
The RetrieveFileRequest 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 TranslationFileResult object contains the following information:
Name | Type | Description |
---|---|---|
fileContent |
IncomingMessage | IncomingMessage representing the translated file content. This is populated all the time even if the translated content is stored in an output file on the disk, based on the outputDir and outputFile values. |
requestId |
string | Translation request identifier |
For more information about the API, access: File Translations.
Browser JavaScript Environment
try {
const clientConfiguration = new ClientConfiguration();
clientConfiguration.credentialsConfiguration = new CredentialsConfiguration(clientId, clientSecret);
const lwClient = await SdkFactory.getLanguageWeaverClient(clientConfiguration);
const request = new RetrieveFileRequest();
request.requestId = "requestId";
const translateFileResult = await lwClient.retrieveFileTranslation(request);
console.log(translateFileResult.fileContent);
} catch (e) {
console.log(e);
}
See the complete sample on GitHub.
The RetrieveFileRequest 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 TranslationFileResult 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. |
For more information about the API, access: File Translations.
Content Insights
Create Content Insights For Existing Translations
The getContentInsightsForTranslations method from LanguageWeaverClient performs content insights for a file that was already translated.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const contentInsightsRequest = new ContentInsightsRequest();
contentInsightsRequest.addTranslationId("translationId");
const contentInsightsResult = await lwClient.getContentInsightsForTranslations(contentInsightsRequest);
console.log(contentInsightsResult);
} catch (e) {
console.log(e);
}
See the complete samples on GitHub:
Note
When you perform content insights for existing translation, you need to disable "Content deletion" and enable "Content Insights" from your account settings
The ContentInsightsRequest object contains the following information:
Name | Type | Mandatory | Default value | Description |
---|---|---|---|---|
translationIds |
string array | yes | A string array containing translation ids |
The ContentInsightsResult object contains the following information:
Name | Type | Description |
---|---|---|
summarization |
Summarization | Object containing the sentences from the input files that were selected as part of the summary |
The Summarization object contains the following information:
Name | Type | Description |
---|---|---|
segments |
Segment array | The array with the sentences from the input files that were selected as part of the summary |
The Segment 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 |
score |
number | A score between 0 and 1. The higher the score, the more representative the sentence is for the summary |
Note
If Edge product is selected, you can perform content insights for only one file that was already translated. If you want to perform content insights for multiple files, please use CloudLanguageWeaverClient!
Feedback Management
Get All Feedback
By using the getFeedback method from LanguageWeaverClient, the list of available feedback will be returned, corresponding to the given client identifier.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const filterRequest = new FilterFeedbackRequest();
filterRequest.startDate = "10-04-2022";
filterRequest.endDate = "10-24-2022";
filterRequest.approvalStatus = ApprovalStatus.APPROVED;
filterRequest.user = "123";
const feedbackResult = await lwClient.getFeedback(1, 50, filterRequest);
// handle result
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The getFeedback 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 |
FilterFeedbackRequest | no | String specifying the criteria by which the returned feedback to be filtered |
The FilterFeedbackRequest 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 | |
approvalStatus |
ApprovalStatus | no | The approval status of the feedback (APPROVED, REJECTED, PENDING) | |
user |
string | no | The id of the user who created the feedback (Cloud) or the username of the user who created the feedback (Edge) |
The FeedbackListResult object contains the following information:
Name | Type | Description |
---|---|---|
feedbackList |
FeedbackResult array | Contains a list of FeedbackResult 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 FeedbackResult 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 |
approvalState |
ApprovalStatus | The approval status of the feedback (APPROVED, REJECTED, PENDING) |
feedbackAuditData |
AuditData | An object representing the details about the lifecycle of the feedback |
approvalAuditData |
AuditData | An object representing the details about the lifecycle of the feedback approval status |
The AuditData object contains the following information:
Name | Type | Description |
---|---|---|
createdByUserEmail |
string | The email of the user who created the feedback |
creationDate |
string | Creation date of 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 createFeedback method from LanguageWeaverClient can be used to add a new translation feedback.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const createRequest = new CreateFeedbackRequest();
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.";
const feedbackResult = await lwClient.createFeedback(createRequest);
// handle result
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The CreateFeedbackRequest 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 |
The FeedbackResult 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 |
approvalState |
ApprovalStatus | The approval status of the feedback (APPROVED, REJECTED, PENDING) |
feedbackAuditData |
AuditData | An object representing the details about the lifecycle of the feedback |
approvalAuditData |
AuditData | An object representing the details about the lifecycle of the feedback approval status |
The AuditData object contains the following information:
Name | Type | Description |
---|---|---|
createdByUserEmail |
string | The email of the user who created the feedback |
creationDate |
string | Creation date of 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 updateFeedback method from LanguageWeaverClient can be used to update an existing translation feedback.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const updateRequest = new UpdateFeedbackRequest();
updateRequest.feedbackId = "e8b01170-1bc4-4d61-89f7-fc2f65733442";
updateRequest.suggestedTranslation = "Ceci est un exemple de texte d'entrée.";
const feedbackResult = await lwClient.updateFeedback(updateRequest);
// handle result
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The UpdateFeedbackRequest object contains the following information:
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
feedbackId |
string | yes | Feedback identifier | |
suggestedTranslation |
string | no | Expected translation |
The FeedbackResult 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 |
approvalState |
ApprovalStatus | The approval status of the feedback (APPROVED, REJECTED, PENDING) |
feedbackAuditData |
AuditData | An object representing the details about the lifecycle of the feedback |
approvalAuditData |
AuditData | An object representing the details about the lifecycle of the feedback approval status |
The AuditData object contains the following information:
Name | Type | Description |
---|---|---|
createdByUserEmail |
string | The email of the user who created the feedback |
creationDate |
string | Creation date of 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 updateFeedbackApproval method from LanguageWeaverClient can be used to update the approval status of an existing translation feedback.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const updateRequest = new UpdateFeedbackApprovalRequest();
updateRequest.feedbackId = "e8b01170-1bc4-4d61-89f7-fc2f65733442";
updateRequest.approvalStatus = ApprovalStatus.APPROVED;
const feedbackResult = await lwClient.updateFeedbackApproval(updateRequest);
// handle result
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The UpdateFeedbackApprovalRequest 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 FeedbackResult 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 |
approvalState |
ApprovalStatus | The approval status of the feedback (APPROVED, REJECTED, PENDING) |
feedbackAuditData |
AuditData | An object representing the details about the lifecycle of the feedback |
approvalAuditData |
AuditData | An object representing the details about the lifecycle of the feedback approval status |
The AuditData object contains the following information:
Name | Type | Description |
---|---|---|
createdByUserEmail |
string | The email of the user who created the feedback |
creationDate |
string | Creation date of 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 deleteFeedback method from LanguageWeaverClient can be used to delete an existing translation feedback.
try {
const lwClient = await SdkFactory.getLanguageWeaverClient(new ClientConfiguration());
const deleteRequest = new DeleteFeedbackRequest();
deleteRequest.feedbackId = "e8b01170-1bc4-4d61-89f7-fc2f65733442";
await lwClient.deleteFeedback(deleteRequest);
} catch (e) {
// handle errors
}
See the complete samples on GitHub:
The DeleteFeedbackRequest object contains the following information:
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
feedbackId |
string | yes | Feedback identifier |
For more information about the API, access: Delete Feedback.