This package is under active development. You can get more information about WebTranslateIt API using this link https://webtranslateit.com/en/docs/api/.
To install this package, please, use default go get tool
go get github.com/fromYukki/webtranslateit_go_client
Authentication is made by so-called API tokens, and of course you need specify this one of the token to the WebTranslateIt
structure.
import wti_client "github.com/fromYukki/webtranslateit_go_client"
func main() {
wti := wti_client.NewWebTranslateIt("YOUR_TOKEN")
project, err := wti.GetProject()
if err != nil {
panic(err)
}
}
If you need to change API URL address or Token you can do it using next methods: SetApiUrl
and SetToken
.
Project API section has only one method Show Project. You can read about it here.
As shown in the example above, you can get the project and use it data as you wish. For more information, please, take a look on Project
structure.
import (
"fmt"
wti_client "github.com/fromYukki/webtranslateit_go_client"
)
func main() {
wti := wti_client.NewWebTranslateIt("YOUR_TOKEN")
project, err := wti.GetProject()
if err != nil {
panic(err)
}
fmt.Printf("Project name: %q with %d files", project.Name, len(project.ProjectFiles))
}
Only one method is implemented in the File API section. The rest you can find here.
The easiest method to get all the translation files - is to download them in Zip archive.
import (
"fmt"
wti_client "github.com/fromYukki/webtranslateit_go_client"
)
func main() {
var (
err error
project wti_client.Project
zipFile wti_client.ProjectZipFile
data map[string][]byte
)
wti := wti_client.NewWebTranslateIt("YOUR_TOKEN")
if project, err = wti.GetProject(); err != nil {
panic(err)
}
if zipFile, err = project.ZipFile(); err != nil {
panic(err)
}
if data, err = zipFile.Extract(); err != nil {
panic(err)
}
for fileName, fileData := range data {
fmt.Printf("Extracted file %q with %d bytes length", fileName, len(fileData))
}
}