trGo

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

trGo is a rich package for translating a text with a specified language (or detecting it automatically) to another specified language (default is english). It has a simple algorithm (and a readable code).

Index

Constants

View Source
const (
	TrCmd          = "tr"
	DoubleQS       = BackSlash + DoubleQ
	DoubleQSP      = DoubleQS + CAMA
	NonEscapeN     = "\\n"
	NonEscapeNV    = NonEscapeN + CAMA
	HttpRm         = "af.httprm"
	E4Value        = "\"e\"" + CAMA + "4" + CAMA
	NullCValue     = NullStr + CAMA
	GenericStr     = CAMA + "\"generic\""
	NullCValueR    = CAMA + NullStr
	NeQ            = "\\n\""
	NullN          = "\n\"" + CAMA + "null"
	DiValue        = "\"di\""
	AkCloseQ       = "}'"
	WrbFr          = "\"wrb.fr\",\"" + rpcValue + "\""
	BoldOpen       = "\\u003cb\\u003e"
	BoldClose      = "\\u003c/b\\u003e"
	MiddleWave     = DoubleQSP + DoubleQS
	WrongNessOpen  = `\\u003cb\\u003e\\u003ci\\u003e`
	WrongNessClose = `\\u003c/i\\u003e\\u003c/b\\u003e`
	ExampleFirst   = "null,\"\\u003cb\\u003e"
	ThreeE         = DoubleBackSlash + "u003e"
	CeeE           = DoubleBackSlash + "u003c"
	QuetUnicode    = "u0026#39;"
	StrAndCama     = DoubleQS + CAMA
	StringAndCama  = DoubleQ + CAMA
	CamaAndStr     = CAMA + DoubleQS
	NullAndCama    = NullStr + CAMA
	TwoCama        = CAMA + CAMA
	TwoStr         = DoubleQ + DoubleQ
	CamaNullCama   = CAMA + NullStr + CAMA
)
View Source
const (
	LineChar   = '-' // line : '-'
	EqualChar  = '=' // equal: '='
	SpaceChar  = ' ' // space: ' '
	DPointChar = ':' // double point: ':'
)
View Source
const (
	GET_SLASH       = "/"
	HTTP_ADDRESS    = ":"
	FORMAT_VALUE    = "%v"
	SPACE_VALUE     = " "
	LineEscape      = "\n"
	R_ESCAPE        = "\r"
	SEMICOLON       = ";"
	CAMA            = ","
	ParaOpen        = "("
	ParaClose       = ")"
	NullStr         = "null"
	DoubleQ         = "\""
	SingleQ         = "'"
	DoubleQJ        = "”"
	BracketOpen     = "["
	Bracketclose    = "]"
	Star            = "*"
	BackSlash       = "\\"
	DoubleBackSlash = "\\\\"
	Point           = "."
	AutoStr         = "auto"
	AtSign          = "@"
	EqualStr        = "="
	DdotSign        = ":"
)

router config values

View Source
const (
	DY           = "$"
	WOTO_TEXT    = "WOTO_TEXT"
	DY_WOTO_TEXT = DY + WOTO_TEXT
)

dynamic values

View Source
const (
	BIN_FLAG     = "bin"
	BINARY_FLAG  = "binary"
	PV_FLAG      = "pv"
	PRIVATE_FLAG = "private"
	TEXT_FLAG    = "text"
	TXT_FLAG     = "txt"
	TO_FLAG      = "to"
	FR_FLAG      = "fr"
	FROM_FLAG    = "from"
	GNU_FLAG     = "gnu"
)

the flags for the wotoTranslate plugin. please notice that all flags should begin with prefix --, but in the pTools, this prefix will be removed.

Variables

View Source
var MinConfidence float32 = 8.0

Functions

func IsKind

func IsKind(value string) bool

func SimpleTranslate

func SimpleTranslate(fr, to, text string) (string, error)

Types

type Corrected

type Corrected struct {
	// an array of the corrected parts of the
	// original input text
	CorrectedParts []string

	// whole string
	CorrectedValue string
}

type Kind

type Kind string
const (
	Verb Kind = "verb"
	Noun Kind = "noun"
)

type Lang

type Lang struct {
	Data *LangData `json:"data"`
}

Lang struct contains data of the language.

func DetectLanguage

func DetectLanguage(text string) *Lang

DetectLanguage will detect the language of a text.

func (*Lang) GetBest

func (l *Lang) GetBest() *LangDetect

func (*Lang) IsEmpty

func (l *Lang) IsEmpty() bool

type LangData

type LangData struct {
	Detections []LangDetect `json:"detections"`
}

LangData contains the data of the language.

type LangDetect

type LangDetect struct {
	TheLang    string  `json:"language"`
	Reliable   bool    `json:"isReliable"`
	Confidence float32 `json:"confidence"`
}

LangDetect contains the detected languages.

type WotoTr

type WotoTr struct {
	// Pronunciation of the original text
	OriginalPronunciation string

	// Pronunciation of the translated text
	TranslatedPronunciation string
	UserText                string

	// Translations is an array of translated string recieved from
	// google's servers
	Translations []string
	From         string
	To           string
	Corrected    *Corrected
	HasWrongness bool

	// public wrong from.
	// if 'From' in user's inpur is not correct,
	// this field will be true.
	HasWrongFrom bool

	Kind []string
	// contains filtered or unexported fields
}

WotoTr contains necessary fields for results of a transtion operation.

func Translate

func Translate(to, text string) (*WotoTr, error)

func TranslateIt

func TranslateIt(lang *Lang, to, text string) (*WotoTr, error)

Translate will translate the specified text value tp english.

func TranslateText

func TranslateText(fr, to, text string) (*WotoTr, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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