Giter Site home page Giter Site logo

Add LibreTranslate about ballonstranslator HOT 2 OPEN

mr-grixa avatar mr-grixa commented on June 9, 2024
Add LibreTranslate

from ballonstranslator.

Comments (2)

bropines avatar bropines commented on June 9, 2024

I made a connection to the local Libre Translate for myself. Hastily done, the url and api key are not editable. I got the list of languages through the AI chatbot, but I didn't check everything.

from .base import *
import requests

@register_translator('LibreTranslate')
class LibreTranslator(BaseTranslator):

    concate_text = False
    params: Dict = {
    }

    def _setup_translator(self):
        self.lang_map['العربية'] = 'ar'
        self.lang_map['Azərbaycan dili'] = 'az'
        self.lang_map['中文'] = 'zh'
        self.lang_map['繁體中文'] = 'zht'
        self.lang_map['čeština'] = 'cs'
        self.lang_map['Dansk'] = 'da'
        self.lang_map['Nederlands'] = 'nl'
        self.lang_map['English'] = 'en'
        self.lang_map['Esperanto'] = 'eo'
        self.lang_map['Suomi'] = 'fi'
        self.lang_map['Français'] = 'fr'
        self.lang_map['Deutsch'] = 'de'
        self.lang_map['Ελληνικά'] = 'el'
        self.lang_map['עברית'] = 'he'
        self.lang_map['हिन्दी'] = 'hi'
        self.lang_map['magyar nyelv'] = 'hu'
        self.lang_map['Bahasa Indonesia'] = 'id'
        self.lang_map['Gaeilge'] = 'ga'
        self.lang_map['Italiano'] = 'it'
        self.lang_map['日本語'] = 'ja'
        self.lang_map['ⵜⴰⵇⴱⴰⵢⵍⵉⵜ'] = 'kab'
        self.lang_map['한국어'] = 'ko'
        self.lang_map['occitan'] = 'oc'
        self.lang_map['پارسی'] = 'fa'
        self.lang_map['Polski'] = 'pl'
        self.lang_map['Português'] = 'pt'
        self.lang_map['русский язык'] = 'ru'
        self.lang_map['slovenčina'] = 'sk'
        self.lang_map['Español'] = 'es'
        self.lang_map['Svenska'] = 'sv'
        self.lang_map['Türkçe'] = 'tr'
        self.lang_map['українська мова'] = 'uk'
        self.lang_map['Tiếng Việt'] = 'vi'
        

    def _translate(self, src_list: List[str]) -> List[str]:
        # URL of the LibreTranslate API server
        url = "http://localhost:5000/translate"
        # Empty list to store the translated strings
        result = []
        # Loop through the source list
        for src in src_list:
            # Make a POST request to the API with the source string and the languages
            response = requests.post(url, data={"q": src,
                                    "source": self.lang_map[self.lang_source],
                                    "target": self.lang_map[self.lang_target],
                                    "format": "text",
                                    "api_key": ""})
            # Check if the response is successful
            if response.ok:
                # Parse the JSON response and get the translated text
                translated = response.json()["translatedText"]
                # Append the translated text to the result list
                result.append(translated)
            else:
                # Handle the error
                print(f"Request failed with status code: {response.status_code}")
                print(f"Response text: {response.text}")
        # Return the result list
        return result

chat gpt help? :)

from ballonstranslator.

mr-grixa avatar mr-grixa commented on June 9, 2024

chat gpt help? :)

claude

from ballonstranslator.

Related Issues (20)

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.