A web server with a RESTful API to translate a text from one language to another. There is implementation of cache using Redis in order to avoid repeated hits to the translation API.
Nodejs
Express framework
Redis (For caching & smart caching)
Heroku-cli for deploying it to Heroku
- vitalets/google-translate-api (for translating text)
- ISO-639-1 (for detecting language code)
- Mocha for testing
Clone the repo
Replace existing credentials with your redis credentials in config.js
Type npm start in terminal to start the server
To get the translation, we can use Postman or any web browser and hit this API as follows:
{URL}/translate?sourceText=&targetLanguage=&sourceLanguage=
# URL: (http://localhost:3000) or https://immense-anchorage-24441.herokuapp.com
Type npm test in terminal to test the API
- Translates the text from source language to target language
- Implements caching for repeated api hits
- Implements pre-caching for similar language.For eg.If a person looks for translation in Kannada,he may likely to look for translation in Hindi,Tamil,Telugu.So when he searches for tanslation in kannada,system smartly caches the text in Hindi,Tamil,Telugu,etc
- Expiration time of each data is set in cache
- Used Express framework
- User enters text,source language and target language he wants to translate it to
- Middleware folder contains the middleware of cache that act as a check before moving to the controller, if key is present in Redis then it would return the value and not move to the translation else if not found it will be feeded to translation API for translation
- vitalets/google-translate-api module is used to translate the text. Text,source and target language code are passed as parameters to translate function provided by this module and in response we get the translated text
- ISO-639-1 is used to convert language name to language code which would be feeded to translation APi
- This translated text is cached to reduce response time of repeated api hits
- For similar languages a list of related languages is stored in smartcache
- Smart pre-cache function is being called in the translate text function in which related languages of the entered language are checked, translated and stored in cache
- Evaluation of the results is done by comparing the response time of the api(refer screensots)
- Deployed it on Heroku to make it accessible to everyone on the interet
- Mocha is used for testing.Three test scenarios have been taken into consideration.
1)Correct Input
2)Wrong Language name entered
3)Not text entered for translation
First time API call for a particular word and language

Smart Pre-Caching
Incorrect Language Name


