gtranslate

package module
v0.0.0-...-2ca3b22 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 10 Imported by: 0

README

gtranslate

Google Translate API for unlimited and free translations 📢.

Install

go get github.com/ystyle/gtranslate

Use

// set google domain (if you need)
gtranslate.SetGoogleDomain("https://translate.google.cn")

// translate
gtranslate.Translate("I'm alive", language.English, language.Spanish)
gtranslate.TranslateWithParams("I'm alive", gtranslate.TranslateWithParams{From: "en", To: "es"})

Example

package main

import (
	"fmt"
	"github.com/ystyle/gtranslate"
	"time"
)

func main() {
	text := "Hello World"
	start := time.Now()
	translated, err := gtranslate.TranslateWithParams(
		text,
		gtranslate.TranslationParams{
			From: "en",
			To:   "zh",
		},
	)
	if err != nil {
		panic(err)
	}

	fmt.Printf("en: %s | zh: %s | time: %s\n", text, translated, time.Now().Sub(start))
	// en: Hello World | zh: 你好,世界 | time: 547.2785ms
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGoogleDomain

func SetGoogleDomain(url string)

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 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

Jump to

Keyboard shortcuts

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