Skip to content

Commit a04432c

Browse files
committed
add documents
1 parent fb83533 commit a04432c

File tree

6 files changed

+124
-1
lines changed

6 files changed

+124
-1
lines changed

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# go-deeplapi
2+
3+
## Usage
4+
5+
### AS CLI TOOL
6+
7+
```sh
8+
$ go install github.com/micheam/go-deeplapi/cmd/translate@latest
9+
```
10+
11+
```sh
12+
$ translate こんにちわ、世界
13+
Hello, World
14+
```
15+
16+
Please run `-help` for detailed usage.
17+
18+
```
19+
$ translate -help
20+
Usage of translate:
21+
translate [flags] [text]
22+
Flags:
23+
--api-domain string
24+
Domain for DeepL API. (Default) Environment variable: 'DEEPL_API_DOMAIN'
25+
Use 'api.deepl.com' if not set.
26+
--auth-key string
27+
Authentication Key for DeepL API. (Default) Environment variable: 'DEEPL_AUTH_KEY'
28+
--list-lang
29+
Display a list of LANG_CODE that can be specified.
30+
--source string
31+
LANG_CODE of the text to be translated. If it is omitted, it will be determined automatically.
32+
--target string
33+
LANG_CODE of the text to be translated. (default 'EN')
34+
Examples:
35+
$ translate --soruce ja --taget en 'あんなこといいな。できたらいいな'
36+
$ echo 'あんなこといいな。できたらいいな' | translate # source lang will auto-detected
37+
```
38+
39+
### AS GO MODULE
40+
41+
```sh
42+
$ go get github.com/micheam/go-deeplapi/v2
43+
```
44+
45+
```go
46+
package main
47+
48+
import (
49+
"context"
50+
"fmt"
51+
52+
"github.com/micheam/go-deeplapi/v2"
53+
)
54+
55+
func main() {
56+
57+
const authKey = "YOUR-DEEPL-AUTH-KEY"
58+
client := deeplapi.New(authKey)
59+
service := deeplapi.NewTextTranslatingService(client)
60+
61+
var (
62+
text = "こんにちわ、世界"
63+
source = deeplapi.LangJapanese
64+
target = deeplapi.LangEnglish
65+
)
66+
67+
res, _ := service.TraslateSingleText(context.Background(), text, source, target)
68+
fmt.Println(res.Text)
69+
// Output: Hello, World
70+
}
71+
```
72+
73+
## Requirements
74+
75+
- go 1.19 or higher
76+
77+
## Installation
78+
79+
```sh
80+
$ go install github.com/micheam/go-deeplapi/cmd/translate
81+
```
82+
83+
## License
84+
85+
MIT
86+
87+
## Author
88+
89+
[Michito Maeda](https://github.com/micheam)

example/go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/micheam/go-deeplapi/example
2+
3+
go 1.19
4+
5+
replace github.com/micheam/go-deeplapi => ../
6+
7+
require github.com/micheam/go-deeplapi v0.0.0-00010101000000-000000000000

example/go.sum

Whitespace-only changes.

example/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/micheam/go-deeplapi/v2"
8+
)
9+
10+
func main() {
11+
12+
const authKey = "YOUR-DEEPL-AUTH-KEY"
13+
client := deeplapi.New(authKey)
14+
service := deeplapi.NewTextTranslatingService(client)
15+
16+
var (
17+
text = "こんにちわ、世界"
18+
source = deeplapi.LangJapanese
19+
target = deeplapi.LangEnglish
20+
)
21+
22+
res, _ := service.TraslateSingleText(context.Background(), text, source, target)
23+
fmt.Println(res.Text)
24+
// Output: Hello, World
25+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/micheam/go-deeplapi
22

3-
go 1.16
3+
go 1.19

v2/translating_text.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"log"
78
"net/http"
89
"net/url"
910
"strings"
@@ -110,6 +111,7 @@ type TraslateSingleTextResult struct {
110111
}
111112

112113
func (t TextTranslatingService) TraslateSingleText(ctx context.Context, text string, source, target Lang) (*TraslateSingleTextResult, error) {
114+
log.Println("base url: " + BaseURL())
113115
_url := strings.Join([]string{BaseURL(), APIVersion, PathTextTranslating}, "/")
114116
param := url.Values{
115117
"text": []string{text},

0 commit comments

Comments
 (0)