xtranslate

package
v0.5.18 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YouDao = "YouDao"
	Baidu  = "Baidu"
	Google = "Google"
	Deepl  = "Deepl"
)

Variables

View Source
var BasePlatformTranslateConf map[string][]map[string]*gvar.Var

BasePlatformTranslateConf 基础平台翻译配置

View Source
var BaseTranslateConf map[string]map[string]string

BaseTranslateConf 基础翻译配置

View Source
var InitPlatformConfFunc = initPlatformConfHandler

InitPlatformConfFunc 初始化平台配置

View Source
var InitTranslateBaseConf = func() map[string]map[string]string {
	translate := gfile.GetContents("./translate.json")

	if translate == "" {
		return nil
	}

	json, err := gjson.DecodeToJson(translate)

	if err != nil {
		return nil
	}

	m := make(map[string]map[string]string, 1)

	for s, v := range json.Var().MapStrVar() {
		m[s] = v.MapStrStr()
	}

	return m
}

InitTranslateBaseConf 初始化翻译基础配置

View Source
var TranslateDebug = func() bool {

	get, err := g.Cfg().Get(gctx.New(), "server.translateDebug", false)

	if err != nil {
		panic(fmt.Sprintf("翻译初始化失败 %s", err))
	}

	return get.Bool()
}()

Functions

func BaiduTranslate

func BaiduTranslate(BaiduConfig *BaiduConfigType, from, to, text string) (result []string, fromLang string, err error)

func DeeplTranslate

func DeeplTranslate(config *DeeplConfigType, from, to, text string) (result []string, fromLang string, err error)

func GetYouDaoLang

func GetYouDaoLang(lang, app string) (string, error)

func GoogleTranslate

func GoogleTranslate(config *GoogleConfigType, from, to, text string) (result []string, fromLang string, err error)

GoogleTranslate google 翻译

func InitTranslate

func InitTranslate()

func SafeLangType

func SafeLangType(t, app string) (string, error)

func YouDaoTranslate

func YouDaoTranslate(YouDaoConfig *YouDaoConfigType, from, to, text string) (result []string, fromLang string, err error)

YouDaoTranslate 有道翻译

Types

type BaiduConfigType

type BaiduConfigType struct {
	CurlTimeOut int    `json:"curlTimeOut"`
	Url         string `json:"url"`
	AppId       string `json:"appId"`
	Key         string `json:"key"`
}

BaiduConfigType 百度的配置类型

type DeeplConfigType

type DeeplConfigType struct {
	CurlTimeOut int    `json:"curlTimeOut"`
	Url         string `json:"url"`
	Key         string `json:"key"`
}

DeeplConfigType Deepl配置类型

type GoogleConfigType

type GoogleConfigType struct {
	CurlTimeOut int    `json:"curlTimeOut"`
	Url         string `json:"url"`
	Key         string `json:"key"`
}

GoogleConfigType 谷歌配置类型

type TranslationResData

type TranslationResData struct {
	From string `json:"from"` // 原文语言
	To   string `json:"to"`   // 翻译后语言
	Text string `json:"text"` // 原文
}

TranslationResData 翻译数据

type TranslationRespData

type TranslationRespData struct {
	Result  []string `json:"result"`  // 翻译后内容
	From    string   `json:"from"`    // 实际原文语言
	FromLen int      `json:"fromLen"` // 翻译原文字数
	ToLen   []int    `json:"toLen"`   // 翻译后文字字数
	To      string   `json:"to"`      // 翻译后语言
	Tool    string   `json:"tool"`    // 翻译工具
}

func Translation

func Translation(t *TranslationResData, cfg ...map[string][]map[string]*gvar.Var) (*TranslationRespData, error)

Translation 翻译

type YouDaoConfigType

type YouDaoConfigType struct {
	CurlTimeOut int    `json:"curlTimeOut"`
	Url         string `json:"url"`
	AppKey      string `json:"appKey"`
	SecKey      string `json:"secKey"`
}

YouDaoConfigType 有道配置类型

Jump to

Keyboard shortcuts

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