Convert Figma logo to code with AI

UlionTse logotranslators

Translators is a library that aims to bring free, multiple, enjoyable translations to individuals and students in Python. 「翻译官」是一个旨在用Python为个人和学生带来免费、多样、愉快翻译的库。

2,386
248
2,386
12

Top Related Projects

(unofficial) Googletrans: Free and Unlimited Google translate API for Python. Translates totally free of charge.

A flexible free and unlimited python tool to translate between different languages in a simple way using multiple translators.

A free and unlimited API for Google Translate :dollar::no_entry_sign:

Free and Open Source Machine Translation API. Self-hosted, offline capable and easy to setup.

Quick Overview

UlionTse/translators is a Python library that provides a unified API for multiple translation services. It supports various translation engines including Google, Bing, Yandex, and others, allowing developers to easily integrate translation capabilities into their applications without being tied to a single service provider.

Pros

  • Supports multiple translation services through a single API
  • Easy to switch between different translation engines
  • Provides both free and paid translation options
  • Actively maintained with regular updates

Cons

  • Some translation services may require API keys or have usage limits
  • Performance may vary depending on the chosen translation engine
  • Limited to the languages supported by each individual service
  • May require additional setup for certain translation engines

Code Examples

  1. Basic translation using Google Translate:
import translators as ts

text = "Hello, world!"
result = ts.google(text, from_language='en', to_language='es')
print(result)  # Outputs: "¡Hola Mundo!"
  1. Switching between different translation engines:
import translators as ts

text = "How are you?"
result_bing = ts.bing(text, from_language='en', to_language='fr')
result_yandex = ts.yandex(text, from_language='en', to_language='fr')

print(f"Bing: {result_bing}")
print(f"Yandex: {result_yandex}")
  1. Detecting the language of a text:
import translators as ts

text = "Bonjour, comment allez-vous?"
detected_lang = ts.google(text, to_language='en', if_use_cn_host=False, if_detect_language=True)
print(f"Detected language: {detected_lang}")

Getting Started

To get started with UlionTse/translators, follow these steps:

  1. Install the library using pip:

    pip install translators
    
  2. Import the library in your Python script:

    import translators as ts
    
  3. Use the desired translation engine function:

    result = ts.google("Hello", from_language='en', to_language='fr')
    print(result)
    

Note: Some translation services may require API keys or additional setup. Refer to the project's documentation for specific requirements and usage instructions for each supported translation engine.

Competitor Comparisons

(unofficial) Googletrans: Free and Unlimited Google translate API for Python. Translates totally free of charge.

Pros of py-googletrans

  • Simpler API with fewer dependencies
  • Faster execution for single language translations
  • Lightweight and easy to integrate into existing projects

Cons of py-googletrans

  • Limited to Google Translate service only
  • Less reliable due to potential changes in Google's API
  • Fewer features and customization options

Code Comparison

py-googletrans:

from googletrans import Translator
translator = Translator()
result = translator.translate('Hello', dest='es')
print(result.text)

translators:

import translators as ts
result = ts.google('Hello', to_language='es')
print(result)

Key Differences

translators offers support for multiple translation services, including Google, Bing, Yandex, and others. It provides a more comprehensive solution for developers who need flexibility in choosing translation providers.

py-googletrans is focused solely on Google Translate, making it a simpler option for those who only need this specific service.

translators has more robust error handling and fallback mechanisms, which can be crucial for production environments. It also offers additional features like language detection and pronunciation.

Overall, translators is more suitable for complex, multi-lingual projects, while py-googletrans may be preferable for simpler, Google-specific translation needs.

A flexible free and unlimited python tool to translate between different languages in a simple way using multiple translators.

Pros of deep-translator

  • More extensive language support, covering over 100 languages
  • Offers multiple translation engines beyond Google Translate
  • Includes speech-to-text and text-to-speech capabilities

Cons of deep-translator

  • Slower performance for bulk translations
  • Less comprehensive documentation and examples
  • Fewer options for customizing API requests

Code Comparison

deep-translator:

from deep_translator import GoogleTranslator
translated = GoogleTranslator(source='auto', target='es').translate("Hello, world!")

translators:

import translators as ts
translated = ts.google("Hello, world!", to_language='es')

Both libraries offer simple interfaces for translation, but deep-translator requires explicit instantiation of a translator object, while translators uses a more functional approach. translators generally provides a more concise syntax for basic translation tasks.

deep-translator shines in scenarios requiring multiple translation engines or speech-related features, while translators excels in performance-critical applications and offers more flexibility in API interactions.

A free and unlimited API for Google Translate :dollar::no_entry_sign:

Pros of google-translate-api

  • Lightweight and focused specifically on Google Translate
  • Simple API with straightforward usage
  • Supports both free and paid Google Translate API options

Cons of google-translate-api

  • Limited to Google Translate only, while translators supports multiple services
  • Less actively maintained compared to translators
  • Fewer features and customization options

Code Comparison

translators:

from translators import translate_text

result = translate_text('Hello, world!', to_language='es')
print(result)  # Hola Mundo!

google-translate-api:

const translate = require('google-translate-api');

translate('Hello, world!', {to: 'es'}).then(res => {
    console.log(res.text);  // Hola Mundo!
}).catch(err => {
    console.error(err);
});

Both repositories provide translation functionality, but translators offers a more comprehensive solution with support for multiple translation services. google-translate-api is simpler and more focused on Google Translate specifically. The choice between them depends on whether you need a multi-service solution or prefer a lightweight, Google-specific option.

Free and Open Source Machine Translation API. Self-hosted, offline capable and easy to setup.

Pros of LibreTranslate

  • Self-hosted solution, offering more privacy and control over data
  • Supports multiple translation engines, including Argos Translate and OpenNMT
  • Provides a user-friendly web interface for easy translation

Cons of LibreTranslate

  • Limited language support compared to translators
  • May require more setup and maintenance as a self-hosted solution
  • Potentially slower translation speed, especially for large-scale tasks

Code Comparison

LibreTranslate:

from libretranslatepy import LibreTranslateAPI

lt = LibreTranslateAPI("https://translate.argosopentech.com/")
result = lt.translate("Hello, world!", "en", "es")
print(result)

translators:

import translators as ts

result = ts.google("Hello, world!", from_language="en", to_language="es")
print(result)

LibreTranslate offers a more privacy-focused approach with self-hosting capabilities, while translators provides a wider range of translation services and languages. LibreTranslate may be preferred for organizations with strict data control requirements, whereas translators is more suitable for developers seeking a variety of translation options and broader language support in a single package.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

PyPI - Version Conda - Version PyPI - License PyPI - Python PyPI - Status PyPI - Wheel PyPI - Downloads


Translators is a library that aims to bring free, multiple, enjoyable translations to individuals and students in Python.

Supported Translation Services

IDTranslatorNumber of Supported LanguagesAdvantageServiceStatus
1Niutrans452support the most languages in the worldNortheastern University / Niutrans, China/
2MyMemory330support the most languages in the worldTranslated, Italystable
3Alibaba221support most languages, support professional fieldAlibaba, Chinastable
4Lara211support the most languages in the worldTranslated, Italystable
5Baidu201support most languages, support professional field, support classical ChineseBaidu, Chinastable
6ModernMt200open-source, support more languages in the worldModernmt / Translated, Italystable
7VolcEngine189support more languages in the world, support professional fieldByteDance, China/
8Iciba187support the most languages in the worldKingsoft / Xiaomi, Chinastable
9Iflytek137support the most languages in the worldIflytek, China/
10Google134support more languages in the worldGoogle, Americastable(offline in China inland)
11Bing128support more languages in the worldMicrosoft, Americastable
12Lingvanex112support translation of different regions but the same languageLingvanex, Cyprusstable
13Yandex102support more languages in the world, support word to emojiYandex, Russiastable
14Itranslate101support translation of different regions but the same language, such as en-US, en-UK, en-AUItranslate, Austriastable
15xunjie68support more languages in the worldxunjie, Chinastable
16SysTran52support more languages in the worldSysTran, Francestable
17Argos46open-sourceArgos / Libre, Americastable
18Apertium45open-sourceApertium, Spainstable
19Reverso42popular on Mac and IphoneReverso, Francestable
20Deepl30high quality to translate but response slowlyDeepl, Germanystable
21CloudTranslation28support main languagesXiamen University / CloudTranslation, Chinastable
22QQTranSmart22support main languagesTencent, Chinastable
23TranslateCom21good at English translationTranslateCom, Americastable
24Sogou20support more languages in the worldTencent, Chinastable
25Tilde20good at lv, de, fr translationTilde, Latvia/
26Caiyun19high quality to translate but response slowly, support professional fieldColorfulClouds, Chinastable
27QQFanyi17support main languagesTencent, China/
28TranslateMe16good at English translationTranslateMe / Neosus, Lithuania/
29Papago15good at Korean translationNaver, South Koreastable
30Mirai15good at Japanese translationMiraiTranslate, Japan/
31Youdao12support main languages, high qualityNetease, Chinastable
32Iflyrec12good at Chinese translationIflytek, Chinastable
33Hujiang12supported by baiduHujiang, Chinastable
34Yeekit10support main languagesCTC, China/
35LanguageWire8good at English translationLanguageWire, Denmarkstable
36Elia6good at Basque translationElhuyar, Spainstable
37Judic4good at European translationCrossLang, Belgium/
38Mglip3good at Mongolia translationInner Mongolia University, China/
39Utibet2good at Tibet translationTibet University, Chinastable

Installation

# PYPI
pip install --upgrade translators

# Conda (Not recommended)
conda install conda-forge::translators

# Source
git clone https://github.com/UlionTse/translators.git
cd translators
python setup.py install

Getting Started

import translators as ts

q_text = '季姬寂,集鸡,鸡即棘鸡。棘鸡饥叽,季姬及箕稷济鸡。'
q_html = '''<!DOCTYPE html><html><head><title>《季姬击鸡记》</title></head><body><p>还有另一篇文章《施氏食狮史》。</p></body></html>'''

### usage
_ = ts.preaccelerate_and_speedtest()  # Optional. Caching sessions in advance, which can help improve access speed.

print(ts.translators_pool)
print(ts.translate_text(q_text))
print(ts.translate_html(q_html, translator='alibaba'))

### parameters
help(ts.translate_text)

"""
translate_text(query_text: str, translator: str = 'bing', from_language: str = 'auto', to_language: str = 'en', **kwargs) -> Union[str, dict]
    :param query_text: str, must.
    :param translator: str, default 'alibaba'.
    :param from_language: str, default 'auto'.
    :param to_language: str, default 'en'.
    :param if_use_preacceleration: bool, default False.
    :param **kwargs:
            :param is_detail_result: bool, default False.
            :param http_client: str, default 'requests' (except reverso). Union['requests', 'niquests', 'httpx', 'cloudscraper']
            :param professional_field: str, default None. Support alibaba(), baidu(), caiyun(), cloudTranslation(), elia(), sysTran(), youdao(), volcEngine() only.
            :param timeout: Optional[float], default None.
            :param proxies: Optional[dict], default None.
            :param sleep_seconds: float, default 0.
            :param update_session_after_freq: int, default 1000.
            :param update_session_after_seconds: float, default 1500.
            :param if_use_cn_host: bool, default False. Support google(), bing() only.                
            :param reset_host_url: str, default None. Support google(), yandex() only.
            :param if_check_reset_host_url: bool, default True. Support google(), yandex() only.
            :param if_ignore_empty_query: bool, default False.
            :param limit_of_length: int, default 20000.
            :param if_ignore_limit_of_length: bool, default False.
            :param if_show_time_stat: bool, default False.
            :param show_time_stat_precision: int, default 2.
            :param if_print_warning: bool, default True.
            :param lingvanex_mode: str, default 'B2C', choose from ("B2C", "B2B").
            :param myMemory_mode: str, default "web", choose from ("web", "api").
    :return: str or dict
"""

Command Line Interface

You can leverage a simple CLI named fanyi that ships with translators.

>fanyi --help                                                                                                                                                                                                                               ─╯
usage: fanyi input [--text_file] [--translator] [--from] [--to] [--is_html] [--version] [--help]

Translators(fanyi for CLI) is a library that aims to bring free, multiple, enjoyable translations to individuals and students in Python.

positional arguments:
  input                 inputs to be translated.

options:
  --text_file           path to a file to be translated.
  --translator          e.g. bing, google, yandex, etc...
  --from                from_language, default `auto` detected.
  --to                  to_language, default `en`.
  --is_html             is_html, default `0`.
  --version             show version information.
  --help                show help information.

Supported Languages

LanguageLanguage of TranslatorGoogleYandexBingBaiduAlibabaTencentYoudaoSogouDeeplCaiyunArgosothers...
englishenYYYYYYYYYYY...
chinesezhYYYYYYYYYYY
arabicarYYYY(ara)YYYYY
russianruYYYYYYYYYYY
frenchfrYYYY(fra)YYYYYYY
germandeYYYYYYYYY
spanishesYYYY(spa)YYYYYYY
portugueseptYYY(pt/pt-pt)YYYYYYY
italianitYYYYYYYYYY
japanesejaYYYY(jp)YYYYYY
koreankoYYYY(kor)YYYY
greekelYYYYYY
dutchnlYYYYYYY
hindihiYYYYYY
turkishtrYYYYYYY
malaymsYYYYY
thaithYYYYYYY
vietnameseviYYYY(vie)YYYYY
indonesianidYYYYYYYY
hebrewheY(iw)YYY
polishplYYYYYYY
mongolianmnYY
czechcsYYYYYY
hungarianhuYYYYYY
estonianetYYYY(est)YY
bulgarianbgYYYY(bul)YY
danishdaYYYY(dan)YY
finnishfiYYYY(fin)YY
romanianroYYYY(rom)YY
swedishsvYYYY(swe)YY
slovenianslYYYY(slo)YY
persian/farsifaYYYY
bosnianbsYYY(bs-Latn)Y(bs-Latn)
serbiansrYYY(sr-Latn/sr-Cyrl)Y(sr-Latn/sr-Cyrl)
fijianfjYY
filipinotlYYY(fil)Y(fil)
haitiancreolehtYYYY
catalancaYYYY
croatianhrYYYY
latvianlvYYYYY
lithuanianltYYYYY
urduurYYYY
ukrainianukYYYY
welshcyYYYY
tahitityYY
tongantoYY
swahiliswYYYY
samoansmYYY
slovakskYYYYY
afrikaansafYYYY
norwegiannoYYYY
bengalibnYYY(bn-BD)Y
malagasymgYYYY
maltesemtYYYY
queretaro otomiotqYY
klingon/tlhingan holtlhYY
gujaratiguYYY
tamiltaYYY
teluguteYYY
punjabipaYYY
amharicamYY
azerbaijaniazYY
bashkirbaY
belarusianbeYY
cebuanocebYY
chuvashcvY
esperantoeoYY
basqueeuYY
irishgaYYY
emojiemjY
......

About Chinese Language

LanguageLanguage of TranslatorGoogleYandexBingBaiduAlibabaTencentYoudaoSogouIcibaIflytekCaiyunDeeplArgosItranslateReversoTranslateComPapagoUtibet
Chinese(简体)zh-CHSY(zh-CN)Y(zh)Y(zh-Hans)Y(zh)Y(zh)Y(zh)YYY(zh)Y(zh)Y(zh)Y(zh)Y(zh)Y(zh-CN)Y(zh/chi)...Y(zh-CN)Y(zh)
Chinese(繁体)zh-CHTY(zh-TW)Y(zh-Hant)Y(cht)Y(zh-TW)YY(cnt)Y(zh-TW)Y(zh-TW)
Chinese(文言文)wywY
Chinese(粤语)yueYYYYYY(zh-HK)
Chinese(内蒙语)mnN[外蒙]N[外蒙]Y[内蒙]N[外蒙]
Chinese(维吾尔语)uyY
Chinese(藏语)tiYY
Chinese(白苗文)mwwYYY
Chinese(彝语)iiY
Chinese(苗语)hmnY
Chinese(壮语)zyb

Debug Tips

Linux Runtime Environment

  1. To support javascript runtime environment, you should download and install Node.js.
  2. Function baidu() doesn't work on Linux without desktop.

HttpError 4xx

  1. Check whether you made high frequency requests, especially httperror 429.
  2. Check whether this service is provided in your region.
  3. Detail to solve HttpError itself.
  4. Issue me, thanks.

NetworkError or ProxyError

  1. Check whether the network is connected correctly.
  2. Check the proxy are enabled on your computer. If it is enabled, try turning it off or otherwise.

Star History

Star History Chart