googletrans

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: MIT

README

Googletrans

language Documentation Go Report Card

G文⚡️: Concurrency-safe, free and unlimited golang library that implemented Google Translate API.

Inspired by py-googletrans.

Features

  • Out of the box
  • Auto language detection
  • Customizable service URL

Installation

go get -u github.com/mind1949/googletrans

Usage

Detect language

package main

import (
	"fmt"

	"github.com/mind1949/googletrans"
)

func main() {
	detected, err := googletrans.Detect("hello googletrans")
	if err != nil {
		panic(err)
	}

	format := "language: %q, confidence: %0.2f\n"
	fmt.Printf(format, detected.Lang, detected.Confidence)
}

// Output:
// language: "en", confidence: 1.00

Translate

package main

import (
	"fmt"

	"github.com/mind1949/googletrans"
	"golang.org/x/text/language"
)

func main() {
	params := googletrans.TranslateParams{
		Src:  "auto",
		Dest: language.SimplifiedChinese.String(),
		Text: "Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. ",
	}
	translated, err := googletrans.Translate(params)
	if err != nil {
		panic(err)
	}
	fmt.Printf("text: %q \npronunciation: %q", translated.Text, translated.Pronunciation)
}

// Output:
// text: "Go是一种开放源代码编程语言,可轻松构建简单,可靠且高效的软件。"
// pronunciation: "Go shì yī zhǒng kāifàng yuán dàimǎ biānchéng yǔyán, kě qīngsōng gòujiàn jiǎndān, kěkào qiě gāoxiào de ruǎnjiàn."

Customize service URLs

package main

import "github.com/mind1949/googletrans"

func main() {
	serviceURLs := []string{
		"https://translate.google.com/",
		"https://translate.google.pl/"}
	googletrans.Append(serviceURLs...)
}

Directories

Path Synopsis
Package tk generates google translate tk
Package tk generates google translate tk
Package tkk gets google translate tkk
Package tkk gets google translate tkk
Package transcookie just for caching google translation services' cookies
Package transcookie just for caching google translation services' cookies

Jump to

Keyboard shortcuts

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