Giter Site home page Giter Site logo

translation-caching's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.