google_translate

package module
v0.0.0-...-78336c1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 13 Imported by: 0

README

google-translate

A free and unlimited API for Google Translate

Parts of the code are ported from gtranslate and google-translate-api (also MIT license).

Notice

This fork is for testing purpose, tracking the original repo for updates.

Features

  • Auto language detection
  • Spelling correction
  • Language correction
  • Fast and reliable – it uses the same servers that translate.google.com uses

Install

go get github.com/elvuel/google-translate

API

Example
package main

import (
	"encoding/json"
	"fmt"
	gtranslate "github.com/elvuel/google-translate"
)

func main()  {
	translated, err := gtranslate.ManualTranslate("Welcome back", "en-US", "zh-CN")
	if err != nil {
		panic(err)
	} else {
		prettyJSON, err := json.MarshalIndent(translated, "", "\t")
		if err != nil {
			panic(err)
		}
		fmt.Println(string(prettyJSON))
	}
}
Returns an object:
  • text (string) – The translated text.
  • pronunciation (string) – The Pronunciation text.
  • from (object)
    • language (object)
      • did_you_mean (boolean) - true if the API suggest a correction in the source language
      • iso (string) - The code of the language that the API has recognized in the text
    • text (object)
      • auto_corrected (boolean)true if the API has auto corrected the text
      • value (string) – The auto corrected text or the text with suggested corrections
      • did_you_mean (boolean)true if the API has suggested corrections to the text

License

MIT © Gilang Adi S

Documentation

Index

Constants

View Source
const (
	HOST = "google.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type TranslateFrom

type TranslateFrom struct {
	Language TranslateFromLanguage `json:"language"`
	Text     TranslateFromText     `json:"text"`
}

type TranslateFromLanguage

type TranslateFromLanguage struct {
	DidYouMean bool   `json:"did_you_mean"`
	Iso        string `json:"iso"`
}

type TranslateFromText

type TranslateFromText struct {
	AutoCorrected bool    `json:"auto_corrected"`
	Value         *string `json:"value"`
	DidYouMean    bool    `json:"did_you_mean"`
}

type Translated

type Translated struct {
	Text          string        `json:"text"`
	Pronunciation *string       `json:"pronunciation"`
	From          TranslateFrom `json:"from"`
}

func ManualTranslate

func ManualTranslate(text, fromLanguage, toLanguage string) (*Translated, error)

func Translate

func Translate(text, toLanguage string) (*Translated, error)

func TranslateWithParam

func TranslateWithParam(value params.Translate) (*Translated, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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