Skip to content

For using Google Translate if you're too cool to use the Google Translate app

Notifications You must be signed in to change notification settings

nickbouldien/translate-on-the-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Translate on the Go

Inspiration

I'm always looking up words/phrases (usually en español ou em português).

(I know this is pointless since a thing called Google Translate exists, but this is a way for me to mess around with Go on something I might use at one point or another.)

Setup:

  • go install
  • go build
  • ./translate-on-the-go
  • test it out on port 5000 (or whatever endpoint/port you decide to use) with one of the routes

Routes:

  • GET / - Index route - responds with the available routes
  • GET /list-languages?target={target_language_code} - lists all possible languages to translate to
  • POST /translate - translate text to a target language

target language code info: https://cloud.google.com/translate/docs/languages

Sample requests:

1 - list languages with a target of english (en)

request:

curl --request GET \
  --url 'http://localhost:5000/list-languages?target=en'

response (truncated here for display purposes):

[
  {
    "Name": "Afrikaans",
    "Tag": "af"
  },
  {
    "Name": "Albanian",
    "Tag": "sq"
  },
  {
    "Name": "Amharic",
    "Tag": "am"
  },
  {
    "Name": "Arabic",
    "Tag": "ar"
  }
]

2 - translate the word "hello" from english to português

request:

curl --request POST \
  --url http://localhost:5000/translate \
  --header 'content-type: application/json' \
  --data '{
	"lang": "pt",
	"text": "hello"
}'

response:

{
  "response": {
    "sourceLanguage": "en",
    "targetLanguage": "pt",
    "translatedText": "Olá"
  }
}

3 - the index/base route to list the available routes

request:

curl --request GET --url http://localhost:5000/

response:

{
  "routes": {
    "/list-languages": "GET",
    "/translate": "POST"
  }
}

Resources:

About

For using Google Translate if you're too cool to use the Google Translate app

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages