-
Notifications
You must be signed in to change notification settings - Fork 654
Expand file tree
/
Copy pathlanguage_translator.v3.js
More file actions
45 lines (37 loc) · 1.01 KB
/
language_translator.v3.js
File metadata and controls
45 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
require('dotenv').config();
const LanguageTranslatorV3 = require('ibm-watson/language-translator/v3');
/**
* Instantiate the Watson Language Translator Service
*/
const languageTranslator = new LanguageTranslatorV3({
// See: https://github.com/watson-developer-cloud/node-sdk#authentication
// iam_apikey: 'INSERT YOUR IAM API KEY HERE',
version: '2020-04-30',
});
const params = {
text: 'Hello, this is a example of translating language with Watson.',
source: 'en',
target: 'es',
};
// return the body - primary use case
languageTranslator
.translate(params)
.then(body => {
console.log(JSON.stringify(body, null, 2));
console.log('\n');
})
.catch(err => {
console.log(err);
});
// return the entire response - in the case that more
// information (such as response headers) is required
params.return_response = true;
languageTranslator
.translate(params)
.then(res => {
console.log(JSON.stringify(res, null, 2));
})
.catch(err => {
console.log(err);
});