From 79bdd3a88742838d92e65fff2864d4ac0aeafc10 Mon Sep 17 00:00:00 2001 From: nidhal baccouri Date: Fri, 12 Feb 2021 18:41:04 +0100 Subject: [PATCH] fixed bug in google_trans --- deep_translator/google_trans.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deep_translator/google_trans.py b/deep_translator/google_trans.py index 5ad860c..853b0c0 100644 --- a/deep_translator/google_trans.py +++ b/deep_translator/google_trans.py @@ -105,7 +105,7 @@ def translate(self, text, **kwargs): element = soup.find(self._element_tag, self._alt_element_query) if not element: raise TranslationNotFound(text) - if element.get_text(strip=True) == text: + if element.get_text(strip=True) == text.strip() and text.strip().replace(' ', '').isalpha(): self._url_params["tl"] = self._target del self._url_params["hl"] return self.translate(text) @@ -173,5 +173,5 @@ def translate_batch(self, batch=None): if __name__ == '__main__': - txt =GoogleTranslator(source='zh', target='en').translate('好的') # GoogleTranslator(source='hindi', target='en').translate(text="ghar jaana hai") + txt =GoogleTranslator(source='en', target='nl').translate('why not dutch') # GoogleTranslator(source='hindi', target='en').translate(text="ghar jaana hai") print("text: ", txt)