Skip to content

A web server that exposes an API to translate a text

Notifications You must be signed in to change notification settings

shreenanda-8/Translation-Caching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Translation-Caching

ForTheBadge built-with-love

Translation-Caching

A web server that exposes an API to translate a text

Report Bug · Request Feature

Design Decisions

  1. Express framework is used.
  2. Redis is used which works as an in-memory dataset (For caching).
  3. Data is stored in Key-Value pairs.
    __________________________________________________________________
   |____________KEY______________________________VALUE_______________|
   |                                |                                |
   | sourceText:targetLanguage      |        translatedText          |
   |________________________________|________________________________|
  1. controller folder has the functionality to translate the text (With Smart pre-caching).
  2. utils folder has all the middlewares needed (Checks if data is present in the cache or not).
  3. 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.
  4. Then these translated data are sent back to the main process, where pre-caching is performed.
  5. vitalets/google-translate-api module is used to translate the text.
  6. Text and language code are passed as parameters to the API.

Architecture
Architecture

Features

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.

Screenshots

First Hit to the API Second Hit to the API (Caching)
FirstHit SecondHit

Smart Pre-Caching (by providing similar language as a target language)
Smart Caching


Guide to use this API.

Provide your source text and the target language(in ISO 639-1 format) to translate.

For the Reference

Body:
   {
       "source" : "Hello, I am a very good singer",
       "targetLanguage" : "hi"
   }
Result
  {
      "success": true,
      "data": {
         "translatedText": "नमस्ते, मैं एक बहुत अच्छा गायक हूँ"
       },
      "time": "1108 ms"
  }

Setup and Running the Server/App


1. 🔰Clone the Repository

Use the git clone command along with the URL of the repository.
git clone https://github.com/shreenanda-8/Translation-Caching.git
Now we have the copy of the file in our computer.

2. 🔰Download and Run Redis Server in background

This will act as local database for caching.

For Windows users,

Download it from :-
https://github.com/dmajkic/redis/downloads
Download the first zip and install it in your local windows environment.
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,
Then follow the steps:

Run

cd redis-2.4.5-win32-win64
cd 64bit

and finally run

redis-server

For Linux users,

Use the following command to install homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then run
brew install redis
redis-cli
Now redis server starts running in the background at the PORT 6379.

3. 🔀Navigate to the repository folder

To run the project in your local environment, we have to install all the dependencies first:
This can be done with a simple command
npm install

4. 🔀Run the App in your localhost

Use the following command to run the server locally.
npm run dev
Now server will start running at the PORT 3001

Built With

About

A web server that exposes an API to translate a text

Topics

Resources

Stars

Watchers

Forks