Package: aiogtrans
aiogtransaiogtrans is afreeandunlimitedpython library that implements the Google Translate API asynchronously. This uses theGoogle Translate Ajax APIandhttpxto make api calls.Compatible with Python 3.6+.For details refer to theAPI Documentation.FeaturesFast and semi-reliableUses the same api that google translate usesReverse EngineeredAuto language detectionBulk translationsCustomizable service URLHTTP/2 supportHTTP/2 supportThis library uses httpx for HTTP requests so HTTP/2 is supported by default.You can check if http2 is enabled and working by the._response.http_versionofTranslatedorDetectedobject:>>>(awaittranslator.translate('테스트'))._response.http_version# 'HTTP/2'How does this library work?You may wonder why this library works properly, whereas other approaches such like goslate won't work since Google has updated its translation service recently with a ticket mechanism to prevent a lot of crawler programs.The original fork authorSuhun Haneventually figured out a way to generate a ticket by reverse engineering the obfuscated and minified code used by Google to generate tokenshttps://translate.google.com/translate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>, and implemented this in Python. However, this could be blocked at any time.Why not use googletrans?It seemsSuhun Hanhas abandoned the project, at the time of this writing it's been nearly a year and a half since the last commit.I have decided to move on and update this project.Installation$pipinstallaiogtransBasic UsageIf a source language is not given, google translate attempts to detect the source language.>>>fromaiogtransimportTranslator>>>translator=Translator()>>>awaittranslator.translate('안녕하세요.')# <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>>>>awaittranslator.translate('안녕하세요.',dest='ja')# <Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>>>>awaittranslator.translate('veritas lux mea',src='la')# <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>Customize service URLYou can use another google translate domain for translation. If multiple URLs are provided, the program will randomly choose a domain.>>>fromaiogtransimportTranslator>>>translator=Translator(service_urls=['translate.google.com','translate.google.co.kr',])Advanced Usage (Bulk Translations)You can provide a list of strings to be used to translated in a single method and HTTP session.>>>translations=awaittranslator.translate(['The quick brown fox','jumps over','the lazy dog'],dest='ko')>>>fortranslationintranslations:...print(translation.origin,' -> ',translation.text)# The quick brown fox  ->  빠른 갈색 여우# jumps over  ->  이상 점프# the lazy dog  ->  게으른 개Language DetectionThe detect method, as its name implies, identifies the language used in a given sentence.>>>fromgoogletransimportTranslator>>>translator=Translator()>>>awaittranslator.detect('이 문장은 한글로 쓰여졌습니다.')# <Detected lang=ko confidence=0.27041003>>>>awaittranslator.detect('この文章は日本語で書かれました。')# <Detected lang=ja confidence=0.64889508>>>>awaittranslator.detect('This sentence is written in English.')# <Detected lang=en confidence=0.22348526>>>>awaittranslator.detect('Tiu frazo estas skribita en Esperanto.')# <Detected lang=eo confidence=0.10538048>aiogtrans as a command line application$translate-h

usage:translate[-h][-dDEST][-sSRC][-c]text



PythonGoogleTranslatorasacommand-linetool



positionalarguments:textThetextyouwanttotranslate.



optionalarguments:-h,--helpshowthishelpmessageandexit-dDEST,--destDESTThedestinationlanguageyouwanttotranslate.(Default:en)-sSRC,--srcSRCThesourcelanguageyouwanttotranslate.(Default:auto)-c,--detect



$translate"veritas lux mea"-sla-den[veritas]veritasluxmea->[en]Thetruthismylight[pron.]Thetruthismylight



$translate-c"안녕하세요."[ko,1]안녕하세요.Note on Library UsageDISCLAIMER: this is an unofficial library using the web API of translate.google.com and also is not associated with Google.The maximum character limit on a single text is 15,000.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).Important:If you want to use a stable API, it is highly recommended that you use Google's official translate APIhttps://cloud.google.com/translate/docs.If you get HTTP 5xx error or errors like #6, it's probably because Google has banned your client IP address.ContributingContributions are currently discouraged, I am writing this fork as a personal project and if I ever do decide to open up to contributions I will change this.Of course you're more then welcome to fork this and make your own changesLicenseaiogtransis licensed under the MIT License. The terms are as follows:The MIT License (MIT)Copyright (c) 2022 Ben ZhouPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.