-
Notifications
You must be signed in to change notification settings - Fork 2
/
ai.text.translate.js
82 lines (70 loc) · 2.06 KB
/
ai.text.translate.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const client = require('./index')
// Language detection mode (no `from` parameter)
client.ai.text.translate
.fulfill({ text: "How's it going?", to: 'es' })
.then(console.log)
.catch(console.error)
// Bulk mode
client.ai.text.translate
.fulfill({
text: ['A sample text', 'Hello world'],
from: 'en',
to: 'es',
})
.then(console.log)
.catch(console.error)
// Translation domains
// category `general`
client.ai.text.translate
.fulfill({
text: 'A sample text',
to: 'es',
category: 'general', // <-- specify a domain
provider: 'ai.text.translate.microsoft.translator_text_api.2-0',
})
.then(console.log)
.catch(console.error)
// category `generalnn`
client.ai.text.translate
.fulfill({
text: 'A sample text',
to: 'es',
category: 'generalnn', // <-- specify a domain
provider: 'ai.text.translate.microsoft.translator_text_api.2-0',
})
.then(console.log)
.catch(console.error)
// Specified input format
client.ai.text.translate
.fulfill({
text: '<p>A <div>sample</div> text</p>',
to: 'ru',
format: 'html', // <-- specify input format
provider: 'ai.text.translate.google.translate_api.2-0',
})
.then(console.log)
// more examples on exploring providers in ./explore-providers.js
// Supported languages
// List of supported languages
client.ai.text.translate
.languages({ locale: 'ru' })
.then(console.log)
.catch(console.error)
// Full information on a supported language
client.ai.text.translate
.language('he', { locale: 'ru' })
.then(console.log)
.catch(console.error)
// Setting your own language codes (to be bind to the current Intento api key)
client.settings
.languages({ 'alias-for-es': 'es' })
.then(res => {
console.log('set alias', res)
})
.catch(console.error)
setTimeout(() => {
// All language settings related to the current Intento api key
client.settings.languages().then(res => {
console.log('all aliases', res)
})
}, 3000)