gtranslate

package module
v0.0.0-...-1bd07f6 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2020 License: MIT Imports: 14 Imported by: 66 modules, 63 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.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/bregydoc/gtranslate"
)

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

	fmt.Printf("en: %s | ja: %s \n", text, translated)
	// en: Hello World | ja: こんにちは世界
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GoogleHost = "google.com"

Functions

func Translate

func Translate(text string, from language.Tag, to language.Tag, googleHost ...string) (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
	GoogleHost string
}

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
⌂ 换网址