Home

Awesome

<p align="center"> <img src="https://github.com/UlionTse/translators/blob/master/docs/translators_logo.png" width="500"/> </p> <p align="center"> <a href="https://pypi.org/project/translators"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/translators.svg?color=blue"></a> <a href="https://anaconda.org/conda-forge/translators"><img alt="Conda - Version" src="https://img.shields.io/conda/vn/conda-forge/translators.svg?color=blue"></a> <a href="https://pypi.org/project/translators"><img alt="PyPI - License" src="https://img.shields.io/pypi/l/translators.svg?color=brightgreen"></a> <a href="https://pypi.org/project/translators"><img alt="PyPI - Python" src="https://img.shields.io/pypi/pyversions/translators.svg?color=blue"></a> <a href="https://pypi.org/project/translators"><img alt="PyPI - Status" src="https://img.shields.io/pypi/status/translators.svg?color=brightgreen"></a> <a href="https://pypi.org/project/translators"><img alt="PyPI - Wheel" src="https://img.shields.io/badge/wheel-yes-brightgreen.svg"></a> <a href="https://pypi.org/project/translators"><img alt="PyPI - Downloads" src="https://static.pepy.tech/personalized-badge/translators?period=total&units=international_system&left_text=downloads&left_color=grey&right_color=blue"></a> </p>

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

Installation

# PYPI
pip install --upgrade translators

# Conda
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 'bing'.
    :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 professional_field: str, default None. Support alibaba(), baidu(), caiyun(), cloudTranslation(), elia(), sysTran(), youdao(), volcEngine() only.
            :param timeout: float, default None.
            :param proxies: 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
"""

CLI

You can leverage a simple CLI that ships with translators.

> translate --help                                                                                                                                                                                                                               ─╯
usage: translate [-h] [-p PROVIDER] [-f FROM_LANGUAGE] [-t TO_LANGUAGE] [--version] input

Bring free, multiple, enjoyable translations to individuals and students.

positional arguments:
  input                 Raw text or path to a file to be translated

options:
  -h, --help            show this help message and exit
  -p PROVIDER, --provider PROVIDER
                        Choose one of the supported providers. e.g. bing, google, yandex, bing etc...
  -f FROM_LANGUAGE, --from FROM_LANGUAGE
                        Enforce the language of origin. By default it is auto detected.
  -t TO_LANGUAGE, --to TO_LANGUAGE
                        Set the destination language. Always default to english.
  --version             Show version information and exit.

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

DNS

We support custom DNS server by setting the environment variable NIQUESTS_DNS_URL. See https://niquests.readthedocs.io/en/latest/user/quickstart.html#set-dns-via-environment for more information.

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