A web server that exposes an API to translate a text
Report Bug
·
Request Feature
- Express framework is used.
- Redis is used which works as an in-memory dataset (For caching).
- Data is stored in Key-Value pairs.
__________________________________________________________________
|____________KEY______________________________VALUE_______________|
| | |
| sourceText:targetLanguage | translatedText |
|________________________________|________________________________|
- controller folder has the functionality to translate the text (With Smart pre-caching).
- utils folder has all the middlewares needed (Checks if data is present in the cache or not).
- If there are similar languages, for each language, a child process is forked from the main process and they are simultaneously translated to reduce the response time of the API.
- Then these translated data are sent back to the main process, where pre-caching is performed.
- vitalets/google-translate-api module is used to translate the text.
- Text and language code are passed as parameters to the API.
Architecture |
---|
Feature | Coded? | Description |
---|---|---|
Translate | ✔ | Text translation from one language to another. |
Persistent Caching | ✔ | Caching the translations, to avoid repeated hits to the translation API. |
Smart pre-caching | ✔ | Source text is also translated to similar languages and stored in the cache without affecting the response time of API. |
First Hit to the API | Second Hit to the API (Caching) |
---|---|
Smart Pre-Caching (by providing similar language as a target language) |
---|
{
"source" : "Hello, I am a very good singer",
"targetLanguage" : "hi"
}
{
"success": true,
"data": {
"translatedText": "नमस्ते, मैं एक बहुत अच्छा गायक हूँ"
},
"time": "1108 ms"
}
git clone https://github.com/shreenanda-8/Translation-Caching.git
https://github.com/dmajkic/redis/downloads
After downloading redis zip, extract it and go to the location where you extracted the file (useing command prompt). Once you are in the directory where you extracted the zip,
Run
cd redis-2.4.5-win32-win64
cd 64bit
and finally run
redis-server
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install redis
redis-cli
npm install
npm run dev