Skip to content

fawazahmed0/heroku-google-translate-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Translate API using Heroku

Note: google-trans-new package is broken, hence this will not work, Unless someone fixes it.

This is a free google translate api using Heroku, FastAPI , google-trans-new

This api will auto detect the language and translate it into english(under the hood it uses google-trans-new), if you want to manually assign the source and destination language, you will have to modify the code a little bit. Please refer the above links if you intend to add that functionality.

Steps to setup:

  1. Click at Deploy
  2. Signup and you will get a url something like: https://calm-boy-84008.herokuapp.com , note it down

API Endpoints:

  • Use /translategettext endpoint if you have small text to translate and only want translated text
  • Use /translategetfull endpoint if you have small text to translate and JSON response with other details
  • Use /translateposttext endpoint if you have any length text to translate and only want translated text
  • Use /translatepostfull endpoint if you have any length text to translate and JSON response with other details

Below examples in JavaScript:

Example 1:

// Text to be translated
var text = 'لا أعرف لماذا'
// Use the url here which you got in step 2
 fetch('https://calm-boy-84008.herokuapp.com/translategettext/?query='+encodeURIComponent(text))
.then(response => response.text())
.then(data => console.log(data))

Output in Console:

"I do not know why"

Example 2:

// Text to be translated
var text = 'لا أعرف لماذا'
// Use the url here which you got in step 2
 fetch('https://calm-boy-84008.herokuapp.com/translategetfull/?query='+encodeURIComponent(text))
.then(response => response.json())
.then(data => console.log(data))

Output in Console: "I do not know why"

Example 3:

// text to be translated
var text = 'لا أعرف لماذا'
// Use the url here which you got in step 2
 fetch('https://calm-boy-84008.herokuapp.com/translateposttext',{
  method: 'POST',
  body: JSON.stringify(text)
})
.then(response => response.text())
.then(data => console.log(data))

Output in Console:

"I do not know why"

Example 4:

// text to be translated
var text = 'لا أعرف لماذا'
// Use the url here which you got in step 2
 fetch('https://calm-boy-84008.herokuapp.com/translatepostfull',{
  method: 'POST',
  body: JSON.stringify(text)
})
.then(response => response.json())
.then(data => console.log(data))

Output in Console: "I do not know why"

About

Google Translate API using Heroku

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages