gtranslate

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 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.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