-
Notifications
You must be signed in to change notification settings - Fork 5
/
translation.go
52 lines (40 loc) · 1.14 KB
/
translation.go
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
// Translation definition
package txtai
// Translation definition
type TranslationAPI struct {
api API
}
// Creates a Translation instance.
func Translation(params ...string) TranslationAPI {
return TranslationAPI{NewAPI(params...)}
}
// Translates text from source language into target language.
func (translation *TranslationAPI) Translate(text string, target string, source string) string {
var results string
params := map[string]string {
"text": text,
}
if target != "" {
params["target"] = target
}
if source != "" {
params["source"] = source
}
translation.api.Get("translate", params, &results)
return results
}
// Translates text from source language into target language.
func (translation *TranslationAPI) BatchTranslate(texts []string, target string, source string) []string {
var results []string
params := map[string]interface{} {
"texts": texts,
}
if target != "" {
params["target"] = target
}
if source != "" {
params["source"] = source
}
translation.api.Post("batchtranslate", params, &results)
return results
}