gtranslate

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 14 Imported by: 0

README

gtranslate

GoDoc Test Status

gtranslate is a Go client library for FREE and unlimited access to Google Translate API 💵🚫
Multiple strings could be translated with one HTTP request to the API endpoint.

Installation

go get github.com/frei-0xff/gtranslate

Usage

import "github.com/frei-0xff/gtranslate"
ctx := context.Background()
results, err := gtranslate.Translate(ctx, []string{"Sample sentence."}, language.English, language.French)

Example

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/frei-0xff/gtranslate"
	"golang.org/x/text/language"
)

func main() {
	inputs := []string{"Sample sentence.", "What a wonderful world!"}
	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, time.Duration(time.Second*5))
	defer cancel()
	results, err := gtranslate.Translate(ctx, inputs, language.English, language.French)
	if err != nil {
		panic(err)
	}
	fmt.Println(results)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Translate

func Translate(ctx context.Context, inputs []string, source language.Tag, target language.Tag) ([]string, error)

Translate strings of text from a source language to a target language. All inputs must be in the same language.

The returned strings appear in the same order as the inputs.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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