gtranslate

package module
v0.0.0-...-57827af Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: MIT Imports: 14 Imported by: 0

README

gtranslate build

Google Translate API for unlimited and free translations 📢. This project was inspired by google-translate-api and google-translate-token.

Install

go get github.com/bregydoc/gtranslate

Use

gtranslate.LangDetect("I'm alive", 0, 1)
gtranslate.Translate("I'm alive", language.English, language.Spanish)
gtranslate.TranslateWithParams("I'm alive", gtranslate.TranslateWithParams{From: "en", To: "es"})
gtranslate.TranslatePure("I'm alive", "en", "es")

Example

package main

import (
   "fmt"

	"github.com/clinjie/gtranslate"
)

func main() {
	text := "you are so green."
   
   detectLanguage, confidence, err := gtranslate.LangDetect(text, 0, 1)
   
	if err != nil {
		panic(err)
	}

	fmt.Printf("source text is: %s | detect language is: %s | detect language conf is: %f\n", 
				text, detectLanguage, confidence)

	translateText, err := gtranslate.TranslatePure(text, "en", "zh")

	if err != nil {
		panic(err)
	}

	fmt.Printf("source text is: %s | translate text is: %s\n", 
				text, translateText)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LangDetect

func LangDetect(text string, retries, duration int) (string, float64, error)

LangDetect a text

func Translate

func Translate(text string, from language.Tag, to language.Tag) (string, error)

Translate translate a text using native tags offer by go language

func TranslatePure

func TranslatePure(text, from, to string) (string, error)

TranslatePure translate a text using language strng

func TranslateWithParams

func TranslateWithParams(text string, params TranslationParams) (string, error)

TranslateWithParams translate a text with simple params as string

Types

type TranslationParams

type TranslationParams struct {
	From  string
	To    string
	Tries int
	Delay time.Duration
}

TranslationParams is a util struct to pass as parameter to indicate how to translate

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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