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.62k stars 189 forks source link

[Feature]: Remove the check of `reset_url` in Google's server #124

Closed FunnySaltyFish closed 1 year ago

FunnySaltyFish commented 1 year ago

Expect to happened

Now, the google_api will check whether the reset_url starts with http://translate.google., this makes it impossible to use a mirror site which does not start with it (like mirror-translate-google.mysite.com). I hope to remove this limitation, like

reset_host_url = kwargs.get('reset_host_url', None)
if reset_host_url and reset_host_url != self.host_url:
    # remove the following two lines
    # if not reset_host_url[:25] == 'https://translate.google.':
    #     raise TranslatorError

I've modified it locally and it worked well with a mirror site.

Expected APP Version

a future version

Expected Python Version

=3.6 (Default)

Expected Runtime Environment

NoArch (Default)

Country/Region

China

Expected Output

ts.translate_text(text, "google", source, target, if_use_cn_host=False, reset_host_url='http://google-trans-mirror.mysite.com', **kwargs) # this can work

Code of Conduct

UlionTse commented 1 year ago

Okay, you are right. At that time, I consider the url like https://translate.google.fr. But now .com is enough.

UlionTse commented 1 year ago

I re-understood what you mean, the next version will add a parameter if_check_reset_host_url=True, you can change it to False to use the mirror site.

UlionTse commented 1 year ago

Done in v5.7.1