Skip to main content

A free and unlimited python tools for google translate api.

Project description

google_trans_new

Version 1.1.4

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.4 fixed some bug.


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("./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.transalate('สวัสดีจีน',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.  

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google_trans_new-1.1.4.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_trans_new-1.1.4-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file google_trans_new-1.1.4.tar.gz.

File metadata

  • Download URL: google_trans_new-1.1.4.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.7.4

File hashes

Hashes for google_trans_new-1.1.4.tar.gz
Algorithm Hash digest
SHA256 02c3307af35a55ded09928aa67aa4b3fb4d20d91c91a62adc115a9e1a10efa8e
MD5 ce1856260a58dc05549e00a6d614843a
BLAKE2b-256 5e7c0e5c539b74907bf0671b058048364f5e230673f0d601172b97081084ee1f

See more details on using hashes here.

File details

Details for the file google_trans_new-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: google_trans_new-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.7.4

File hashes

Hashes for google_trans_new-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5df9bd81068dbad727e77970f0efdb308b262ad40c6559cc0ee0048cf8a06a4e
MD5 8cccbf1cb9da9880e910429224afffa9
BLAKE2b-256 804b79a6e4790bc33a6582e571e65802d59b9ea7b397786e15d4fa2246b7e54b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page