A text translator using Google cloud translation API
- Clone this repo using git or downloading zip file.
- Project assumes that you have already installed latest version of
nodejs
(> v10) &mysql
(v8) - Navigate to project directory in terminal & run
npm i
- If you want run this project under development mode run
npm i -D
- Copy
.env.example
template file as.env
and provide values to it. - If you have not installed dev dependencies (
npm i -D
) then provideNODE_ENV=production
otherwiseNODE_ENV=development
- Google API credentials JSON file will be sent via mail, place the file inside
conifg
directory and setGOOGLE_APPLICATION_CREDENTIALS=./config/<credentials_filename>
- To start server
npm start
- To start testing (you may have to run twice)
npm test
curl --request POST \
--url http://localhost:7890/translate \
--header 'content-type: application/json' \
--data '{
"text": "Hello world",
"from": "en",
"to": "hi"
}'
A very first request may take near 20 sec to process, I have tried solve this issue but none worked. I believe this is because of Google's OAuth procedure. Once it has cached the OAuth response next requests will be completed within <2 sec (even for different text input requests) unless if you restart the server.