trans

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host      string
	URI       string
	AppID     string
	Secret    string
	APIKey    string
	FromLang  string
	ToLang    string
	HTTPProto string
}

Config 配置结构体(用于结构体方式初始化)

type Option

type Option func(*trans)

Option 配置选项函数类型

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey 设置 API Key

func WithAppID

func WithAppID(appid string) Option

WithAppID 设置 AppID

func WithFromLang

func WithFromLang(lang string) Option

WithFromLang 设置源语言

func WithHTTPProto

func WithHTTPProto(proto string) Option

WithHTTPProto 设置 HTTP 协议版本

func WithHost

func WithHost(host string) Option

WithHost 设置主机地址

func WithSecret

func WithSecret(secret string) Option

WithSecret 设置 Secret

func WithToLang

func WithToLang(lang string) Option

WithToLang 设置目标语言

func WithURI

func WithURI(uri string) Option

WithURI 设置请求路径

type Trans

type Trans interface {
	Translate(text string) (string, error)
	TranslateWithResult(text string) (*TranslationResult, error)
	Extract(result string) (*TranslationResult, error)
}

Trans 翻译接口

type TranslationResult

type TranslationResult struct {
	Source string `json:"src"` // 源文本
	Target string `json:"dst"` // 翻译结果
}

TranslationResult 翻译结果结构体

type Translator

type Translator = Trans

Translator 是 Trans 的向后兼容别名(v1.0.0 之前包名为 translator)。 推荐直接使用 trans.Trans / trans.New。

func New

func New(options ...Option) Translator

New 创建翻译实例(支持 Option 方式)

func NewWithConfig

func NewWithConfig(config Config) Translator

NewWithConfig 创建翻译实例(支持结构体方式)

Jump to

Keyboard shortcuts

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