import requests,time
import json
from langdetect import detect
from langdetect import detect_langs
from langdetect import DetectorFactory
DetectorFactory.seed =0
class TestApi2():
def test_translat(self):print("--------------在线翻译-------\n")
la=["zh-CHS","zh-CHT","en","ko","ja","fr","de","ru"]
#中简zh-CHS 中繁zh-CHT 英en 韩ko 日ja 粤yue 法fr 德de 俄ru
eg=[
# 有效用例
"今天是一个非常好的天气", # 中简
"真是太遗憾了 ", # 中繁
"Baidu query is worthy of conclusion", # 英
"제주도는 선선하고 화창하고 바람이 가볍고 상쾌하다", # 韩
"東京でチャイナタウン探偵を撮影するのは素晴らしいです", # 日
"Guangzhou propose une variété de petits déjeuners le matin et ils sont tous très délicieux ", # 法
"Italien wird ein dauerhaft neutrales Land", # 德
"Китай дружелюбен к соседним странам", # 俄
# 无效用例
" 12345"," ","a"]
url13 =' '//翻译接口
data13 ={'i':''}
params ={'from':' ','to':' ','salt': myTime,'sign':' ','client':' ','product':'dictpen'}for i in eg:
data13['i']=i
print(data13['i'])
params['client']='dictpen' # 客户唯一标识端
signstr =str(params['client']+ data13['i']+str(params['salt']))
params['sign']= TestApi2.encrypt(signstr) # 调用加密
params['from']=detect(data13['i'])print( params['from'])for j in la:
params['to']=j
print('to:',params['to'])
res13 = requests.post(url=url13, params=params, data=data13).json()print('res13:', res13)TestApi2().test_translat()
运行结果
今天是一个非常好的天气
zh-cn
to: zh-CHS
res13:{'translateResult':['今天是一个非常好的天气'],'errorCode':0,'type':'zh-CHS2zh-CHS'}
to: zh-CHT
res13:{'translateResult':['今天是一個非常好的天氣'],'errorCode':0,'type':'zh-CHS2zh-CHT'}
to: en
res13:{'translateResult':['Today is a very good weather'],'errorCode':0,'type':'zh-CHS2en'}
to: ko
res13:{'translateResult':['오늘 아주 좋은 날씨 입니다'],'errorCode':0,'type':'zh-CHS2ko'}
to: ja
res13:{'translateResult':['今日は良い天気'],'errorCode':0,'type':'zh-CHS2ja'}
to: fr
res13:{'translateResult':['Aujourd’hui, c’est une très bonne météo'],'errorCode':0,'type':'zh-CHS2fr'}
to: de
res13:{'translateResult':['Heute um ein guter'],'errorCode':0,'type':'zh-CHS2de'}
to: ru
res13:{'translateResult':['Сегодн очен прекрасн ден'],'errorCode':0,'type':'zh-CHS2ru'}
真是太遗憾了
zh-cn
to: zh-CHS
res13:{'translateResult':['真是太遗憾了'],'errorCode':0,'type':'zh-CHS2zh-CHS'}
to: zh-CHT
res13:{'translateResult':['真是太遺憾了'],'errorCode':0,'type':'zh-CHS2zh-CHT'}
to: en
res13:{'translateResult':["It's really a shame"],'errorCode':0,'type':'zh-CHS2en'}
to: ko
res13:{'translateResult':['정말 너무 유감 스럽습니다'],'errorCode':0,'type':'zh-CHS2ko'}
to: ja
res13:{'translateResult':['本当に残念ですね'],'errorCode':0,'type':'zh-CHS2ja'}
to: fr
res13:{'translateResult':['Quel dommage'],'errorCode':0,'type':'zh-CHS2fr'}
to: de
res13:{'translateResult':['schade'],'errorCode':0,'type':'zh-CHS2de'}
to: ru
res13:{'translateResult':['Очен жал'],'errorCode':0,'type':'zh-CHS2ru'}
Baidu query is worthy of conclusion
en
to: zh-CHS
res13:{'translateResult':['百度查询是有价值的结论'],'errorCode':0,'type':'en2zh-CHS'}
to: zh-CHT
res13:{'translateResult':['百度查詢是有價值的結論'],'errorCode':0,'type':'en2zh-CHT'}
to: en
res13:{'translateResult':['Baidu query is worthy of conclusion'],'errorCode':0,'type':'en2en'}
to: ko
res13:{'translateResult':['바 이두는 쿼리은 결론의 가치 가 있는 것'],'errorCode':0,'type':'en2ko'}
to: ja
res13:{'translateResult':['百度問い合わせは結論に値する'],'errorCode':0,'type':'en2ja'}
to: fr
res13:{'translateResult':['Baidu query is worthy of conclusion'],'errorCode':30,'type':'en2fr'}
to: de
res13:{'translateResult':['Baidu-Abfrage ist eine Schlussfolgerung wert'],'errorCode':0,'worker':'cache','type':'en2de'}
to: ru
res13:{'translateResult':['Baidu query is worthy of conclusion'],'errorCode':30,'type':'en2ru'}
제주도는 선선하고 화창하고 바람이 가볍고 상쾌하다
ko
to: zh-CHS
res13:{'translateResult':['济州岛是凉爽晴朗,风轻而舒畅。'],'errorCode':0,'type':'ko2zh-CHS'}
to: zh-CHT
res13:{'translateResult':['濟州島是涼爽晴朗,風輕而舒暢。'],'errorCode':0,'type':'ko2zh-CHT'}
to: en
res13:{'translateResult':['Jeju island is sunny and cool breeze light and refreshing.'],'errorCode':0,'type':'ko2en'}
to: ko
res13:{'translateResult':['제주도는 선선하고 화창하고 바람이 가볍고 상쾌하다'],'errorCode':0,'type':'ko2ko'}
to: ja
res13:{'translateResult':['제주도는 선선하고 화창하고 바람이 가볍고 상쾌하다'],'errorCode':30,'type':'ko2ja'}
to: fr
res13:{'translateResult':['L’île de Jeju est ensoleillée, ensoleillée, venteuse et rafraîchissante'],'errorCode':0,'worker':'cache','type':'ko2fr'}
to: de
res13:{'translateResult':['Jeju Island ist sonnig, sonnig, windig und erfrischend'],'errorCode':0,'worker':'remote','type':'ko2de'}
to: ru
res13:{'translateResult':['Остров Чеджу солнечный, солнечный, ветреный и освежающий'],'errorCode':0,'worker':'remote','type':'ko2ru'}
東京でチャイナタウン探偵を撮影するのは素晴らしいです
ja
to: zh-CHS
res13:{'translateResult':['在东京唐人街拍摄的是一个很好的侦探。'],'errorCode':0,'type':'ja2zh-CHS'}
to: zh-CHT
res13:{'translateResult':['在東京唐人街拍攝的是一個很好的偵探。'],'errorCode':0,'type':'ja2zh-CHT'}
to: en
res13:{'translateResult':['Tokyo photographing detective Chinatown in the person.'],'errorCode':0,'type':'ja2en'}
to: ko
res13:{'translateResult':['東京でチャイナタウン探偵を撮影するのは素晴らしいです'],'errorCode':30,'type':'ja2ko'}
to: ja
res13:{'translateResult':['東京でチャイナタウン探偵を撮影するのは素晴らしいです'],'errorCode':0,'type':'ja2ja'}
to: fr
res13:{'translateResult':['Filmer Chinatown Detective à Tokyo est incroyable'],'errorCode':0,'worker':'cache','type':'ja2fr'}
to: de
res13:{'translateResult':['Chinatown Detective in Tokio zu filmen ist erstaunlich'],'errorCode':0,'worker':'cache','type':'ja2de'}
to: ru
res13:{'translateResult':['Съемки детектива Чайнатауна в Токио потрясающие'],'errorCode':0,'worker':'cache','type':'ja2ru'}
Guangzhou propose une variété de petits déjeuners le matin et ils sont tous très délicieux
fr
to: zh-CHS
res13:{'translateResult':['广州一早上早餐品种,它们都非常美味'],'errorCode':0,'type':'fr2zh-CHS'}
to: zh-CHT
res13:{'translateResult':['廣州一早上早餐品種,它們都非常美味'],'errorCode':0,'type':'fr2zh-CHT'}
to: en
res13:{'translateResult':['Guangzhou offers a variety of breakfasts in the morning and they are all very delicious'],'errorCode':0,'worker':'cache','type':'fr2en'}
to: ko
res13:{'translateResult':['광저우는 아침에 다양한 아침 식사를 제공하며 모두 매우 맛있습니다.'],'errorCode':0,'worker':'cache','type':'fr2ko'}
to: ja
res13:{'translateResult':['広州は朝に様々な朝食を提供しており、それらはすべて非常においしいです'],'errorCode':0,'worker':'cache','type':'fr2ja'}
to: fr
res13:{'translateResult':['Guangzhou propose une variété de petits déjeuners le matin et ils sont tous très délicieux'],'errorCode':0,'type':'fr2fr'}
to: de
res13:{'translateResult':['Guangzhou bietet eine Vielzahl von Frühstück am Morgen und sie sind alle sehr köstlich'],'errorCode':0,'worker':'cache','type':'fr2de'}
to: ru
res13:{'translateResult':['Гуанчжоу предлагает разнообразные завтраки по утрам, и все они очень вкусные.'],'errorCode':0,'worker':'cache','type':'fr2ru'}
Italien wird ein dauerhaft neutrales Land
de
to: zh-CHS
res13:{'translateResult':['意大利将是永久中立国家'],'errorCode':0,'type':'de2zh-CHS'}
to: zh-CHT
res13:{'translateResult':['意大利將是永久中立國家'],'errorCode':0,'type':'de2zh-CHT'}
to: en
res13:{'translateResult':['Italy becomes a permanently neutral country'],'errorCode':0,'worker':'cache','type':'de2en'}
to: ko
res13:{'translateResult':['이탈리아는 영구적으로 중립국이 된다'],'errorCode':0,'worker':'cache','type':'de2ko'}
to: ja
res13:{'translateResult':['イタリアは永久に中立的な国になる'],'errorCode':0,'worker':'cache','type':'de2ja'}
to: fr
res13:{'translateResult':['L’Italie devient un pays durablement neutre'],'errorCode':0,'worker':'cache','type':'de2fr'}
to: de
res13:{'translateResult':['Italien wird ein dauerhaft neutrales Land'],'errorCode':0,'type':'de2de'}
to: ru
res13:{'translateResult':['Италия становится постоянно нейтральной страной'],'errorCode':0,'worker':'cache','type':'de2ru'}
Китай дружелюбен к соседним странам
ru
to: zh-CHS
res13:{'translateResult':['中国友好邻国'],'errorCode':0,'type':'ru2zh-CHS'}
to: zh-CHT
res13:{'translateResult':['中國友好鄰國'],'errorCode':0,'type':'ru2zh-CHT'}
to: en
res13:{'translateResult':['Китай дружелюбен к соседним странам'],'errorCode':30,'type':'ru2en'}
to: ko
res13:{'translateResult':['중국은 주변국에 우호적입니다.'],'errorCode':0,'worker':'cache','type':'ru2ko'}
to: ja
res13:{'translateResult':['中国は近隣諸国に友好的である'],'errorCode':0,'worker':'cache','type':'ru2ja'}
to: fr
res13:{'translateResult':['La Chine est amicale avec les pays voisins'],'errorCode':0,'worker':'cache','type':'ru2fr'}
to: de
res13:{'translateResult':['China ist freundlich zu Nachbarländern'],'errorCode':0,'worker':'cache','type':'ru2de'}
to: ru
res13:{'translateResult':['Китай дружелюбен к соседним странам'],'errorCode':0,'type':'ru2ru'}12345