Giter Club home page Giter Club logo

translation-api's Introduction

Translation API

This is a simple Flask application that provides a translation API using python googletrans.

Note on library usage (from googletrans)

  • The maximum character limit on a single text is 15k.
  • Due to limitations of the web version of google translate, this API does not guarantee that the library would work properly at all times. (so please use this library if you don’t care about stability.)
  • If you want to use a stable API, I highly recommend you to use Google’s official translate API.
  • If you get HTTP 5xx error or errors like #6, it’s probably because Google has banned your client IP address.

Installation

  1. Environment

    python==3.10
  2. Clone the repository:

    git clone https://github.com/chienhung1519/translation-api.git
  3. Install the required dependencies:

    pip install -r requirements.txt

Usage

  1. Start the Flask server:

    python translation_app.py --host 0.0.0.0 --port 6868
  2. Send a POST request to http://localhost:6868/translate with the following JSON payload:

    {
        "text": "Hello, world!",
        "target_language": "zh-tw"
    }

    Replace "Hello, world!" with the text you want to translate, and "zh-tw" with the target language code.

  3. The API will respond with the translated text:

    {
        "translated_text": "你好世界!"
    }
  4. Example:

    curl -X POST http://localhost:6868/translate \
        -H 'Content-Type: application/json' \
        -d '{"text":"Hello, world!", "target_language": "zh-tw"}'
    # {"translated_text": "你好世界!"}

translation-api's People

Contributors

chienhung1519 avatar

Watchers

 avatar

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.