✨ Add translation features
This commit is contained in:
@@ -10,16 +10,14 @@ import (
|
||||
|
||||
// TranslationParams 用于指定翻译参数
|
||||
type TranslationParams struct {
|
||||
From string // 源语言
|
||||
To string // 目标语言
|
||||
Tries int // 重试次数
|
||||
Delay time.Duration // 重试延迟
|
||||
From string // 源语言
|
||||
To string // 目标语言
|
||||
Timeout time.Duration // 超时时间
|
||||
}
|
||||
|
||||
// 常量定义
|
||||
const (
|
||||
defaultNumberOfRetries = 2
|
||||
defaultTimeout = 30 * time.Second
|
||||
defaultTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
// TranslatorType 翻译器类型
|
||||
@@ -36,6 +34,12 @@ const (
|
||||
DeeplTranslatorType TranslatorType = "deepl"
|
||||
)
|
||||
|
||||
// LanguageInfo 语言信息结构体
|
||||
type LanguageInfo struct {
|
||||
Code string // 语言代码
|
||||
Name string // 语言名称
|
||||
}
|
||||
|
||||
// Translator 翻译器接口,定义所有翻译器必须实现的方法
|
||||
type Translator interface {
|
||||
// Translate 使用Go语言提供的标准语言标签进行文本翻译
|
||||
@@ -46,6 +50,15 @@ type Translator interface {
|
||||
|
||||
// SetTimeout 设置请求超时时间
|
||||
SetTimeout(timeout time.Duration)
|
||||
|
||||
// GetSupportedLanguages 获取翻译器支持的语言列表
|
||||
GetSupportedLanguages() map[string]LanguageInfo
|
||||
|
||||
// IsLanguageSupported 检查指定的语言代码是否受支持
|
||||
IsLanguageSupported(languageCode string) bool
|
||||
|
||||
// GetStandardLanguageCode 获取标准化的语言代码
|
||||
GetStandardLanguageCode(languageCode string) string
|
||||
}
|
||||
|
||||
// TranslatorFactory 翻译器工厂,用于创建不同类型的翻译器
|
||||
|
Reference in New Issue
Block a user