0.0.27 • Published 1 year ago

@scaler-school-of-technology/bhashini-web-translator v0.0.27

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Web Server

Introduction

This Web Server is a JavaScript web server application that utilizes the Bhashini translation service to translate the content of a given web page from one language to another. This documentation provides an overview of the project structure and key components.

Project Structure

1. index.js

This file serves as the main entry point for the Bhashini Web Translator application. It initializes an Express.js server, handles incoming requests, and utilizes the BhashiniTranslator and fetchHTML modules to translate web content.

Dependencies

  • express: A web application framework for Node.js.
  • @scaler-school-of-technology/bhashini-web-translator: Bhashini translation service client.
  • dotenv: Loads environment variables from a .env file.
  • ./fetchHTML.js: Module for fetching the body element content from a given URL.

2. fetchHTML.js

This module provides functionality to fetch the HTML content of a web page and extract the body element content using Axios for HTTP requests and Cheerio for HTML parsing.

Dependencies

  • axios: A promise-based HTTP client for the browser and Node.js.
  • cheerio: A fast, flexible, and lean implementation of jQuery for the server.

Setup and Configuration

  1. Install dependencies:

    npm install
  2. Create a .env file in the project root with the following variables:

    BHASHINI_API_KEY=<Your Bhashini API Key>
    BHASHINI_USER_ID=<Your Bhashini User ID>

Running the Server

Start the Bhashini Web Translator server by running the following command:

npm start

The server will be accessible at http://localhost:3000.

Endpoints

1. /

  • Method: GET
  • Description: Welcome message for the Bhashini Web Translator app.

2. /translate

  • Method: GET
  • Description: Send the URL of the website to translate in the JSON format. The response will be the translated website
  • Parameters:
    • url (string): The URL of the web page to be translated.

Usage

  1. Access the homepage:

    GET <http://localhost:3000/>
  2. Translate a web page:

    GET <http://localhost:3000/translate?url=><URL_OF_WEB_PAGE>

Limitations

  • The web server is not able to translate websites that use client-side rendering
  • The web server is not able to translate websites that use cookies for authentication.
  • The web server is not able to translate websites that use authentication tokens for authentication tokens for authentication.
  • The web server is not able to translate websites that use sessions for authentication.

Important Notes

  • Ensure that the required environment variables (BHASHINI_API_KEY and BHASHINI_USER_ID) are set in the .env file.
  • The server is set to listen on port 3000 by default. Adjust the app.listen method in index.js if a different port is desired.

Conclusion

This Web Server translates web page content using the Bhashini translation service. Developers can extend and modify the application to meet specific requirements or integrate it into other projects.

0.0.27

1 year ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago