translate

package module
v0.0.0-...-9adffb4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: MIT Imports: 11 Imported by: 0

README

translate

百度翻译API接口

ts := NewBaiduTranslate("xxxx", "xxxxxxx", BaiduHttpsApiGateway)
dst, err := ts.Translate("你好啊", Option{
  From: BZhLang,
  To:   BEnLang,
})
// How do you do

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaiduHttpApiGateway  = "http://api.fanyi.baidu.com/api/trans/vip/translate"
	BaiduHttpsApiGateway = "https://fanyi-api.baidu.com/api/trans/vip/translate"
)

Functions

func GetHttpClient

func GetHttpClient() *http.Client

Types

type BaiduResp

type BaiduResp struct {
	BaiduRespErr
	From        Language `json:"from,omitempty"`
	To          Language `json:"to,omitempty"`
	TransResult []struct {
		SRC string `json:"src"`
		DST string `json:"dst"`
	} `json:"trans_result,omitempty"`
}

type BaiduRespErr

type BaiduRespErr struct {
	ErrorCode int    `json:"error_code,string,omitempty"`
	ErrorMsg  string `json:"error_msg,omitempty"`
}

func (BaiduRespErr) Error

func (b BaiduRespErr) Error() string

type ITranslate

type ITranslate interface {
	Translate(string, Option) (string, error)
}

func NewBaiduTranslate

func NewBaiduTranslate(appID, appSecret, apiGateway string) ITranslate

type Language

type Language string
var (
	BAutoLang Language = "auto"
	BZhLang   Language = "zh"
	BEnLang   Language = "en"
	BJpLang   Language = "jp"
)

type Option

type Option struct {
	From Language
	To   Language
}

Jump to

Keyboard shortcuts

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