Help us shape the future of Go! Take the 2026 Go Developer Survey

translator

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 12 Imported by: 2

README

Googletrans

Sourcegraph

This is Golang version of py-googletrans.

Googletrans is a free and unlimited Golang library that implemented Google Translate API. This uses the Google Translate Ajax API from Chrome extensions to make calls to such methods as detect and translate.

Download from Github

GO111MODULE=on go get github.com/Conight/go-googletrans

Quick Start Example

Simple translate
package main

import (
	"fmt"
	"github.com/Conight/go-googletrans"
)

func main() {
	t := translator.New()
	result, err := t.Translate("你好,世界!", "auto", "en")
	if err != nil {
		panic(err)
	}
	fmt.Println(result.Text)
}
Using proxy
c := translator.Config{
    Proxy: "http://PROXY_HOST:PROXY_PORT",
}
t := translate.New(c)
Using custom service urls or user agent
c := translator.Config{
    UserAgent: []string{"Custom Agent"},
    ServiceUrls: []string{"translate.google.com.hk"},
}
t := translate.New(c)

See Examples for more examples.

Special thanks

License

This SDK is distributed under the The MIT License, see LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ReTkk = regexp.MustCompile(`tkk:'(.+?)'`)

Functions

func New

func New(config ...Config) *translator

func Token

func Token(host string, client *http.Client) *tokenAcquirer

Types

type Config

type Config struct {
	ServiceUrls []string
	UserAgent   []string
	Proxy       string
}

Config basic config.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL