-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdeepl.go
44 lines (42 loc) · 947 Bytes
/
deepl.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
package deepl
import (
"github.com/lib-x/deepl/internal/deeplx"
"github.com/lib-x/deepl/internal/option"
"github.com/lib-x/deepl/internal/rpc"
)
// Translate request data. support lang code using deepL api
// DE: German
// EN: English
// ES: Spanish
// FR: French
// IT: Italian
// JA: Japanese
// NL: Dutch
// PL: Polish
// PT: Portuguese
// RU: Russian
// ZH: Chinese
// BG: Bulgarian
// CS: Czech
// DA: Danish
// EL: Greek
// ET: Estonian
// FI: Finnish
// HU: Hungarian
// LT: Lithuanian
// LV: Latvian
// RO: Romanian
// SK: Slovakian
// SL: Slovenian
// SV: Swedish
func Translate(sourceLanguage, targetLanguage, textToTranslate string, options ...Option) (jsonRpcResponse *rpc.JsonRpcResponse, err error) {
opt := &option.DeepLClientOption{}
for _, apply := range options {
apply(opt)
}
if !opt.UseDeepLPro {
cli := deeplx.New(opt)
return cli.Translate(sourceLanguage, targetLanguage, textToTranslate)
}
return nil, err
}