Skip to main content

google_trans_new

Version 1.1.9

A free and unlimited python API for google translate.
It's very easy to use and solve the problem that the old api which use tk value cannot be used.
This interface is for academic use only, please do not use it for commercial use.

Version 1.1.9 have fixed url translate. Ps: If your get translations for different genders, it will return a list. https://support.google.com/translate/answer/9179237?p=gendered_translations&hl=zh-Hans&visit_id=637425624803913067-1347870216&rd=1


Installation

pip install google_trans_new

Basic Usage

Translate

from google_trans_new import google_translator  
  
translator = google_translator()  
translate_text = translator.translate('สวัสดีจีน',lang_tgt='en')  
print(translate_text)
-> Hello china

Advanced Usage

Translate

from google_trans_new import google_translator  

# You can set the url_suffix according to your country. You can set url_suffix="hk" if you are in hong kong,url_suffix use in https://translate.google.{url_suffix}/ 
# If you want use proxy, you can set proxies like proxies={'http':'xxx.xxx.xxx.xxx:xxxx','https':'xxx.xxx.xxx.xxx:xxxx'}
translator = google_translator(url_suffix="hk",timeout=5,proxies={'http':'xxx.xxx.xxx.xxx:xxxx','https':'xxx.xxx.xxx.xxx:xxxx'})  
# <Translator url_suffix=cn timeout=5 proxies={'http':'xxx.xxx.xxx.xxx:xxxx','https':'xxx.xxx.xxx.xxx:xxxx'}>  
#  default parameter : url_suffix="cn" timeout=5 proxies={}
translate_text = translator.translate('สวัสดีจีน',lang_tgt='zh')  
# <Translate text=สวัสดีจีน lang_tgt=th lang_src=zh>  
#  default parameter : lang_src=auto lang_tgt=auto 
#  API can automatically identify the src translation language, so you don’t need to set lang_src
print(translate_text)
-> 你好中国

Multithreading Translate

from google_trans_new import google_translator
from multiprocessing.dummy import Pool as ThreadPool
import time

pool = ThreadPool(8)  # Threads


def request(text):
    lang = "zh"
    t = google_translator(timeout=5)
    translate_text = t.translate(text.strip(), lang)
    return translate_text


if __name__ == "__main__":
    time1 = time.time()
    with open("tests/test.txt", 'r') as f_p:
        texts = f_p.readlines()
        try:
            results = pool.map(request, texts)
        except Exception as e:
            raise e
        pool.close()
        pool.join()

        time2 = time.time()
        print("Translating %s sentences, a total of %s s" % (len(texts), time2 - time1))
-> Translating
720
sentences, a
total
of
25.89591908454895
s 

Detect

from google_trans_new import google_translator  
  
detector = google_translator()  
detect_result = detector.detect('สวัสดีจีน')
# <Detect text=สวัสดีจีน >  
print(detect_result)
-> ['th', 'thai']

Pronounce

from google_trans_new import google_translator  
  
translator  = google_translator()  
Pronounce = translator.translate('สวัสดีจีน',lang_src='th',lang_tgt='zh',pronounce=True)  
print(Pronounce)
-> ['你好中国 ', 'S̄wạs̄dī cīn', 'Nǐ hǎo zhōngguó']

Prerequisites

  • Python >=3.6
  • requests
  • six

License

google_trans_new is licensed under the MIT License. The terms are as follows:

MIT License  

Copyright (c) 2020 lushan88a  

Permission is hereby granted, free of charge, to any person obtaining a copy  
of this software and associated documentation files (the "Software"), to deal  
in the Software without restriction, including without limitation the rights  
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
copies of the Software, and to permit persons to whom the Software is  
furnished to do so, subject to the following conditions:  

The above copyright notice and this permission notice shall be included in all  
copies or substantial portions of the Software.  

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
LIABILITY, 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 THE  
SOFTWARE.  

Metadata

Release files for google-trans-new-that-works 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for google-trans-new-that-works 0.1.1
File Size Uploaded Provenance Actions
google_trans_new_that_works-0.1.1.tar.gz 8.9 kB Without provenance Details for google_trans_new_that_works-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for google-trans-new-that-works 0.1.1
File Interpreter ABI Platform Actions
google_trans_new_that_works-0.1.1-py3-none-any.whl Python 3 none any Details for google_trans_new_that_works-0.1.1-py3-none-any.whl

Total release size: 18.1 kB

Release files / google_trans_new_that_works-0.1.1.tar.gz

Download URL google_trans_new_that_works-0.1.1.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e900d7b50041c9051e9af62068ef7b6a609132e2c107b25894842c2510545847
BLAKE2b-256 checksum
How to use checksums
e550d5a28255e3c7d88d818337717065d7da54a789880a4c61f0db1d4bdc7351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.1 Windows/10

Release files / google_trans_new_that_works-0.1.1-py3-none-any.whl

Download URL google_trans_new_that_works-0.1.1-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d065e86374c6dda609fba96a6c6dd078db12ac02fe37c77ad7af1fc64ae7cd0
BLAKE2b-256 checksum
How to use checksums
f7fa350440953c387744a96f6d88fcfdc82e27aae58009b3a82d090425fa6c58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.1 Windows/10

Security for google-trans-new-that-works 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page