在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):lushan88a/google_trans_new开源软件地址(OpenSource Url):https://github.com/lushan88a/google_trans_new开源编程语言(OpenSource Language):Python 100.0%开源软件介绍(OpenSource Introduction):google_trans_newVersion 1.1.9A free and unlimited python API for google translate. 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
Basic UsageTranslatefrom google_trans_new import google_translator
translator = google_translator()
translate_text = translator.translate('สวัสดีจีน',lang_tgt='en')
print(translate_text)
-> Hello china Advanced UsageTranslatefrom 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 Translatefrom 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 Detectfrom google_trans_new import google_translator
detector = google_translator()
detect_result = detector.detect('สวัสดีจีน')
# <Detect text=สวัสดีจีน >
print(detect_result)
-> ['th', 'thai'] Pronouncefrom 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
Licensegoogle_trans_new is licensed under the MIT License. The terms are as follows:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论