translate

package
v0.0.0-...-19e3c1d Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLanguageParams

func GetLanguageParams(r *http.Request) (string, string, error)

func ToGoogleResponseBody

func ToGoogleResponseBody(body []byte, _ bool) ([]byte, error)

ToGoogleResponseBody parses the input Lingvanex response and return the JSON response body in Google format.

func ToLingvanexRequest

func ToLingvanexRequest(r *http.Request, serverURL string) (*http.Request, bool, error)

ToLingvanexRequest parses the input Google format translate request and return a corresponding Lingvanex format request.

Types

type LingvanexResponseBody

type LingvanexResponseBody struct {
	SourceText     []string `json:"sourceText"`
	TranslatedText []string `json:"translatedText"`
}

LingvanexResponseBody represents JSON format of Lingvanex response bodies. Translations's size is limited to 1 since multiple translations is not compatible with Google. Format with auto-detect source language:

[
	{
		"detectedLanguage": {"language": "de", "score": 1.0},
		"translations": [{"text": "Hallo", "to": "en"}]
	},
	{
		"detectedLanguage": {"language": "de", "score": 1.0},
		"translations": [{"text": "Welt", "to": "en"}]
	}
]

Format without auto-detect source language:

[
	{
		"translations": [{"text": "Hallo", "to": "en"}]
	},
	{
		"translations": [{"text": "Welt", "to": "en"}]
	}
]

score and to are not saved in this struct because we don't need them to convert to a google format response.

type RequestBody

type RequestBody struct {
	From          string   `json:"source,omitempty"`
	To            string   `json:"target"`
	Data          []string `json:"q"`
	TranslateMode string   `json:"translateMode"`
}

RequestBody represents JSON format of Lingvanex requests.

Jump to

Keyboard shortcuts

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