Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nuveo/translate
Go online translation package
https://github.com/nuveo/translate
Last synced: about 1 month ago
JSON representation
Go online translation package
- Host: GitHub
- URL: https://github.com/nuveo/translate
- Owner: nuveo
- License: mit
- Archived: true
- Created: 2015-07-13T15:42:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-28T15:13:19.000Z (almost 9 years ago)
- Last Synced: 2024-04-22T18:24:23.460Z (8 months ago)
- Language: Go
- Homepage:
- Size: 66.4 KB
- Stars: 33
- Watchers: 32
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go-extra - ARCHIVED - 07-13T15:42:13Z|2016-02-28T15:13:19Z| (Third-party APIs / Fail injection)
README
# Translate
Go online translation package##### Install
`go get github.com/nuveo/translate`## Available Translator API's
* [Microsoft](http://www.microsoft.com/translator/getstarted.aspx)
* or send us the next Translator API :smile:## Usage
```go
package mainimport (
"fmt"
"log"
"github.com/nuveo/translate"
)func main() {
// gettind your credentials here in: http://www.microsoft.com/translator/getstarted.aspx
t := µsoft.AuthRequest{"client_id", "client_secret"}
// Generate a token valid for 10 minutes
tokenResponse := microsoft.GetAccessToken(t)text := "one two three"
from := "en"
to := "pt"toTranslate := µsoft.TextTranslate{
Text: text, From: from, To: to, TokenResponse: tokenResponse,
}// Get translate of text, return the word translated and error
resp, err := microsoft.TranslateText(toTranslate)
if err != nil {
log.Println(err)
}
fmt.Println(resp) // um dois trêstexts := []string{"one two three", "the book on the table"}
toTranslate.Texts = texts// or get translate of array of strings
resps, err := microsoft.TranslateTexts(toTranslate)
if err != nil {
log.Println(err)
}
fmt.Println(resps) // [um dois três o livro em cima da mesa]// Detect the language of texts
detect := []string{"mundo", "world", "monde"}
toTranslate.Texts = detectrespsD, err := microsoft.DetectText(toTranslate)
if err != nil {
log.Println(err)
}
fmt.Println(respsD, toTranslate.Texts) // [es en fr]
}```
### Support to cache with Redis
Now Translate make cache of words translated.
```go
// to activate cache
toTranslate := µsoft.TextTranslate{
Text: text, From: from, To: to, TokenResponse: tokenResponse, Cache: true,
}```