translate

package module
v0.0.0-...-679cb7e Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 1

README

translate

中文文档

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("未找到翻译服务")

Functions

func FormElements

func FormElements(ctx context.Context, name string) []config.Element

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.

func Translate

func Translate(ctx context.Context, name string, cfg *Config) (string, error)

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

func NewConfig(input, from, to, format string) *Config

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) GetAPIConfig

func (c *Config) GetAPIConfig(key string, otherKeys ...string) string

func (*Config) Release

func (c *Config) Release()

Release returns the Config to the pool if it was allocated from one.

func (*Config) Reset

func (c *Config) Reset() *Config

Reset resets all configuration fields to their zero values and returns the Config pointer for method chaining.

func (*Config) SetAPIConfig

func (c *Config) SetAPIConfig(key, value string) *Config

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

type Provider

type Provider struct {
	Name  string
	Title string

	FormElements []config.Element
	// contains filtered or unexported fields
}

func GetProvider

func GetProvider(name string) *Provider

func ListAll

func ListAll() []Provider

func (*Provider) Translate

func (p *Provider) Translate(ctx context.Context, cfg *Config) (string, error)

type Translator

type Translator func(ctx context.Context, cfg *Config) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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