translatekit

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 32 Imported by: 0

README

translate-kit

Shared Go document translation extracted from SkillView (MIT). No UI framework, Keychain, settings file, database or document cache.

Reuse one Client. Pass Config and APIKey for each request. Translate preserves Markdown code and link destinations and returns a complete result or an error; progress reports completed chunks, not model tokens. Applications own consent, file revisions, presentation, credentials and caching. Plain text currently follows the existing Markdown segmentation behavior.

Providers: Google web, Youdao web, LibreTranslate and OpenAI-compatible AI. Legacy Google Cloud remains for compatibility. Web endpoints are unofficial and may change. No automatic provider switching. Limits: 1 MiB document, 4096 chunks, 2 MiB response, 60-second requests; bounded rate-limit retries only. Anonymous Youdao state stays in memory.

Interface localization is NOT shared. This package never reads environment API keys or a Keychain.

Install with go get github.com/sogud/translate-kit@v0.1.0. The source is MIT licensed; see third-party notices for dependency licenses and upstream source links.

Use

client := translatekit.New(translatekit.Options{})
result, err := client.Translate(ctx, translatekit.Request{
    Config: translatekit.Config{
        Provider: "ai", TargetLanguage: "zh-CN",
        BaseURL: baseURL, Model: model,
    },
    APIKey: key, Text: document, Revision: revision,
}, func(progress translatekit.Progress) {
    // Update the app's progress display on its UI thread.
})

Call only after the user requests translation and the app identifies the selected provider. Never log Request or document contents. Keep one client to retain pacing and cooldown; use context cancellation when the reading task is canceled. The application must reject stale results when the file revision or active tab changes. TestConnection(ctx, config, key) translates only the fixed sample Hello. and must also be explicitly requested.

Existing focused checks are split between this module's internal provider checks and SkillView's adapter/integration checks: go test . here; go test ./internal/translation ./internal/app in SkillView. No real provider requests are needed. Tests moved from SkillView retain its MIT attribution.

Documentation

Index

Constants

View Source
const ConnectionMessage = "Could not connect to the service. Check your network and macOS proxy settings, then retry."
View Source
const TimeoutMessage = "The connection timed out. Check your network and macOS proxy settings, then retry."

Messages deliberately omit URLs, credentials, and server response bodies.

Variables

This section is empty.

Functions

func SupportsLanguage

func SupportsLanguage(language string) bool

func Validate

func Validate(config Config) error

func ValidateBaseURL

func ValidateBaseURL(raw string) (*url.URL, error)

Types

type AIResponseError

type AIResponseError struct {
	Diagnostic ResponseDiagnostic
	// contains filtered or unexported fields
}

func (*AIResponseError) Error

func (e *AIResponseError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client owns only network connections, throttling and anonymous Youdao state. Reuse one client per app. It never reads or saves settings, keys or documents.

func New

func New(options Options) *Client

func (*Client) TestConnection

func (s *Client) TestConnection(ctx context.Context, config Config, key string) error

TestConnection sends only the fixed sample Hello. when the caller requests it.

func (*Client) Translate

func (s *Client) Translate(ctx context.Context, request Request, progress ...func(Progress)) (Result, error)

type Config

type Config struct {
	Provider       string
	TargetLanguage string
	BaseURL        string
	LibreURL       string
	Model          string
}

type Options

type Options struct{ GoogleURL, GoogleCloudURL, YoudaoURL string }

Options overrides endpoints for an explicitly selected compatible service. Empty values use the existing Google/Youdao endpoints.

type Progress

type Progress struct {
	RequestID      string `json:"requestId"`
	Completed      int    `json:"completed"`
	Total          int    `json:"total"`
	Provider       string `json:"provider"`
	TargetLanguage string `json:"targetLanguage"`
}

type Request

type Request struct {
	Config   Config
	APIKey   string
	Text     string
	Revision string
}

type ResponseDiagnostic

type ResponseDiagnostic struct {
	Category     string `json:"category"`
	FinishReason string `json:"finish_reason"`
	Truncation   string `json:"truncation"`
}

ResponseDiagnostic contains only fixed categories. It never retains provider responses, prompts, document text, endpoint URLs, model names or API keys.

func (ResponseDiagnostic) Valid

func (d ResponseDiagnostic) Valid() bool

type Result

type Result struct {
	Text           string `json:"text"`
	Provider       string `json:"provider"`
	TargetLanguage string `json:"targetLanguage"`
	Revision       string `json:"revision"`
	Cached         bool   `json:"cached"`
	Sections       int    `json:"sections"`
}

Jump to

Keyboard shortcuts

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