- To create a web server with a RESTful API to translate a text from one language to another, using
Google Cloud Translation
API - To cache translations, in order to avoid repeated hits to the API
- To implement smart pre-caching
- Clone this repository into your local device.
- Go to the project directory and run
npm install
command from your terminal. - Run
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/node-translation-api-6b2091d0fe30.json"
command after giving it the proper file path to thenode-translation-api-6b2091d0fe30.json
file, which will be provided to you separately via e-mail. - Start the server with
node server.js
command. - Listen to
localhost:5000
port to check whether the server is properly running or not. - Submit POST request to the
localhost:5000/translate
endpoint. The request must contain atext
field and atarget
field in its body inx-www-form-urlencoded
format. The Google Cloud Translation API behind the scenes is smart enough to detect the source language. You must mention ISO-639-1 Code of the 'target' language (Reference: https://cloud.google.com/translate/docs/languages) to specificy the language into which you want to translate your text.