Documentation
¶
Index ¶
- Variables
- func FormElements(ctx context.Context, name string) []config.Element
- func RegisterProvider(name string, title string, translate Translator, ...)
- func ReleaseConfig(c *Config)
- func Translate(ctx context.Context, name string, cfg *Config) (string, error)
- type Config
- type Provider
- type Translator
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = fmt.Errorf("未找到翻译服务")
Functions ¶
func RegisterProvider ¶
func RegisterProvider(name string, title string, translate Translator, formElements ...config.Element)
func ReleaseConfig ¶
func ReleaseConfig(c *Config)
ReleaseConfig releases the configuration back to the pool if it was allocated from the pool. If the config was not from the pool, this function does nothing. After releasing, the config is reset to its zero state.
Types ¶
type Config ¶
type Config struct {
Input string
From string
To string
Format string
APIConfig map[string]string
// contains filtered or unexported fields
}
Config is the configuration for the translation service.
func AcquireConfig ¶
func AcquireConfig() *Config
AcquireConfig returns a Config instance from the config pool.
func NewConfig ¶
NewConfig creates a new Config instance with the specified input, source language, target language, and format. The returned Config includes an empty APIConfig map for additional provider-specific settings.
func (*Config) Release ¶
func (c *Config) Release()
Release returns the Config to the pool if it was allocated from one.
func (*Config) Reset ¶
Reset resets all configuration fields to their zero values and returns the Config pointer for method chaining.
func (*Config) SetAPIConfig ¶
SetAPIConfig sets the API configuration value for the given key and returns the Config for chaining.
func (*Config) SetDefaults ¶
func (c *Config) SetDefaults()
SetDefaults initializes the Config's APIConfig map if it is nil