t2

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Name() string
	Translate(text string, source string, pivot string) (backend.TranslationResponse, error)
	Usage() (backend.UsageResponse, error)
}

Backend is the interface that wraps the translation backend methods.

func SelectBackend

func SelectBackend(backend, endPoint, apiKey string) (Backend, error)

SelectBackend returns the translation service implementation to use.

type Clipboard

type Clipboard interface {
	Read() (string, error)
	Write(t string) error
}

Clipboard is the interface that wraps the copy to clipboard functionality.

type Config

type Config struct {
	SourceLang      string
	PivotLang       string
	DiffOnly        bool
	CopyToClipboard bool
}

Config is the configuration of the package.

type Diff

type Diff interface {
	Print(a, b string) string
}

Diff is the interface that wraps the pretty print of the difference between the original text and the double translated text.

type T2

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

T2 is the main struct of the package.

func NewT2

func NewT2(config Config, backend Backend, diff Diff, clipboard Clipboard) T2

NewT2 returns a new T2 struct.

func (T2) Translate

func (t T2) Translate(text string) error

Translate is the main function of the package. It translates the text from the source language to the pivot language, then back to the source language. It then prints the diff between the original text and the double translated text. If the copyToClipboard flag is set, it also copies the double translated text to the clipboard.

Jump to

Keyboard shortcuts

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