Giter Club home page Giter Club logo

voxa-python-docs's Introduction

Voxa

The Voxa Language Translation Service

Voxa is an easy-to-use Python package designed to translate text.

Table of Contents

Getting Started ๐Ÿš€

To get started, install Voxa with pip:

pip install voxa

Usage ๐Ÿ“–

Using Voxa is straightforward. Below is a quick example to translate an English text into French:

import voxa

translator = voxa.Translator(source='en', target='fr')

translated_text = translator.translate("Hello")

print(translated_text)

Multi-tasking ๐Ÿ”ฅ

import voxa

# Create a Translator object with default languages
translator = voxa.Translator(source='en', target='fr')

# Translate "Hello" from English to French
translated_text = translator.translate("Hello")

# For one-off translations with different languages
spanish_translation = translator.translate("Hello", target='es')

print("Translation (English to French):", translated_text)
print("Translation (English to Spanish):", spanish_translation)

Example Usage for a Flask Website ๐ŸŒ

To integrate Voxa in a Flask website, you can set up a simple form for users to input text and then display the translated version. Here's a basic implementation using Flask:

from flask import Flask, render_template_string, request
import voxa

app = Flask(__name__)
translator = voxa.Translator(source='en', target='fr')

TEMPLATE = """
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Translation App</title>
</head>
<body>

<div style="text-align:center; padding: 50px;">
    <h2>Text Translation (EN to FR)</h2>

    <form action="/" method="post">
        <textarea name="text_to_translate" rows="5" cols="50" placeholder="Enter English text here...">{{ original_text }}</textarea>
        <br><br>
        <input type="submit" value="Translate">
    </form>

    <h3>Translation:</h3>
    <textarea rows="5" cols="50" readonly>{{ translation }}</textarea>
</div>

</body>
</html>
"""

@app.route('/', methods=['GET', 'POST'])
def index():
    translation = ""
    original_text = ""

    if request.method == 'POST':
        original_text = request.form.get('text_to_translate')
        if original_text:
            translation = translator.translate(original_text)

    return render_template_string(TEMPLATE, original_text=original_text, translation=translation)

if __name__ == '__main__':
    app.run(debug=True)

Flask Setup For this Flask website, when a user enters text in the textbox and clicks the "Translate" button, the text is sent to the server via a POST request. The server then uses the Voxa to translate the input text from English to French and displays the result back to the user in a readonly textbox.

You can see the file here.

voxa-python-docs's People

Contributors

darktwentyfive avatar

Stargazers

 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.