UlionTse / translators

🌏🌍🌎Translators🌎🌍🌏 is a library that aims to bring free, multiple, enjoyable translations to individuals and students in Python. Translators是一个旨在用Python为个人和学生带来免费、多样、愉快翻译的库。
https://pypi.org/project/translators/
GNU General Public License v3.0
1.63k stars 189 forks source link

TranslateError ; cant find language destination bug on google trad #37

Closed ObedH26 closed 3 years ago

ObedH26 commented 3 years ago

Hello :) im just getting an error on every of my script with this package used; my box just died one week ago and got repair today. I tried 2 different to_language value and getting this error :

Using France server backend. type word here :Nath there is as much possibility: 24

TranslatorError Traceback (most recent call last)

in 28 list2.append(1) 29 list3.append(1) ---> 30 list3[P]=trad(str(list1[P])) 31 32 vo=str(list3[P]).lower() in trad(t) 7 8 def trad(t): ----> 9 u=ts.google(t,to_language='fr',is_detail_result=False) 10 return u 11 /var/mobile/Containers/Data/Application/DE79D566-42C7-4545-B9DE-422DDE1F789C/Library/lib/python3.9/site-packages/translators/apis.py in google_api(self, query_text, from_language, to_language, **kwargs) 328 if not self.language_map: 329 self.language_map = self.get_language_map(host_html) --> 330 from_language, to_language = self.check_language(from_language, to_language, self.language_map, output_zh=self.output_zh) 331 332 rpc_data = self.get_rpc(query_text, from_language, to_language) /var/mobile/Containers/Data/Application/DE79D566-42C7-4545-B9DE-422DDE1F789C/Library/lib/python3.9/site-packages/translators/apis.py in check_language(from_language, to_language, language_map, output_zh, output_auto) 101 raise TranslatorError('Unsupported from_language[{}] in {}.'.format(from_language,sorted(language_map.keys()))) 102 elif to_language not in language_map: --> 103 raise TranslatorError('Unsupported to_language[{}] in {}.'.format(to_language,sorted(language_map.keys()))) 104 elif from_language != output_auto and to_language not in language_map[from_language]: 105 logger.exception('language_map:', language_map) TranslatorError: Unsupported to_language[fr] in []. Thanks mate
ObedH26 commented 3 years ago

Forget to say i runned the command ;pip install translators --upgrade

Its dont change anything

longway4ml commented 3 years ago

Yes, I got the same error. I think it's google change his strategy.

UlionTse commented 3 years ago

@NatHsn26 @longway4ml Hi friends, 截屏2021-04-19 下午12 00 13 截屏2021-04-19 下午12 04 36

The service in China and Singapore has been tested without any problems. Can you tell me where the server address is? And it would be better to provide a copy of the source code of the google translation web page homepage. At present, there is a solution, which is to assign ts._google.language_map={'en':['fr'],'fr':['en']} in the early stage, so that you can avoid the languagemap being empty , Which makes the language check fail.

ObedH26 commented 3 years ago

Hey guys , thanks iam gonna try this this afternoon:)

ObedH26 commented 3 years ago

The ts._google.language_map , returning me an empty list of language, your trick about to assign language to language is working well, i got now a language list of 2 entry, but im using full of the translators so not gonna use it ahah;(. Well i got the same version of the package 4.7.16 and here is the the server adress which is given to me , i think it is same as my first use : 00F3E5F2-5279-44C2-ACD2-6B8132393424 You talking about the last case right ?(Using x server blackened)

And i don’t understand this request sorry need re-explain (im running on iPhone maybe its wont be ok i let you explain me friend ill do what needed) -> : « And it would be better to provide a copy of the source code of the google translation web page homepage. »

UlionTse commented 3 years ago

@NatHsn26 Hi friend, Because the language_map that needs to be verified is obtained from the html source code of the homepage on the web, and it is not available in your region, I want to know how it is different from the code in other places, and then fix this bug.

ObedH26 commented 3 years ago

Ah okok i understand , should i provide you the homepage of the website « https://translate.google.fr/?hl=fr » ? Or other more specify is better(thats the google trad french website main page ). Was working normally just before my wifi break, all information was complete, but yea maybe the problem can be find here idkr ) Should i post the full code of googletranslate french homepage here ? Its a big code i suppose ; i can take a computer on this evening to post the page code here

longway4ml commented 3 years ago

Hi,

In fact I got 404 error when I tried translate.google.cn in the browser.

But I can normally access to translate.google.com in the browser.

ts.google("我爱你",if_use_cn_host=False Or True) -> translators.apis.TranslatorError: Unsupported to_language[en] in [].

ts._google.language_map is empty {}.

I am in Great China.

Thanks.

UlionTse commented 3 years ago

@longway4ml [doc about 4xx] 😂

UlionTse commented 3 years ago

@longway4ml Best to use random sleep_seconds.

ObedH26 commented 3 years ago

Didn’t mind i can put the google trad website code in a file and join it here ,im gonna do this after

UlionTse commented 3 years ago

@NatHsn26 Thanks, friend. But website which to be requested is https://translate.google.com. Or send me emai: shinalone@outlook.com

ObedH26 commented 3 years ago

Okay great gonna do that thanks)

UlionTse commented 3 years ago

@NatHsn26 Hi friend, I want to know, you used the mobile phone to request before, if it is on the computer side, will there be a problem that the language_map cannot be requested? I guess it is caused by the inconsistency between the simulated request header [computer side] and the detected device [mobile side].

ObedH26 commented 3 years ago

Hey ulion ,i am always on phone for it yea because its not my computer;gonna have one in not a bigg while. What i thought to do was to take code from a mac navigator , but also i could ask to see the code of my iphone website on the mac its maybe more appropriate yea. Well so if i understand good the eventual problem ,the translation package is emulating a computer to reach google link right ? I dont know about this in fact but idk i probably changed nothing which is related to this during repairing wifi or on phone.

marwin1991 commented 3 years ago

Same problem here: "Poland"

ObedH26 commented 3 years ago

Same problem here: "Poland"

Hey mate , i can share you the line command to init all language correctly. I did a little script to generate it because its a long command xD

marwin1991 commented 3 years ago

Can you put it on gist a give a link : ) ?