terryyin / translate-python

Online translation as a Python module & command line tool. No key, no authentication needed.
MIT License
732 stars 153 forks source link

Script Fails When Translating from Khmer to English (Not using different provider) #102

Open mcnamara-charles opened 1 year ago

mcnamara-charles commented 1 year ago

When attempting to translate some example text from Khmer to english, the translator fails. It's able to translate English into Khmer I fail to see why it wouldn't be able to do both. Here's the test code that failed

translator= Translator(from_lang="Khmer", to_lang="English")
a_translated = translator.translate("ខ្ញខ្ញុំស្រឡាញ់មាន់")
print(a_translated)

and here's the ensuing error

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\translate\translate.py", line 45, in <genexpr>
    return ' '.join(self.provider.get_translation(text_wraped) for text_wraped in text_list)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\translate\providers\mymemory_translated.py", line 49, in get_translation        
    next_best_match = next(match for match in matches)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "hidden-for-patent-reasons", line 42, in <module>
    a_translated = translator.translate("ខ្ញខ្ញុំស្រឡាញ់មាន់")
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\translate\translate.py", line 45, in translate
    return ' '.join(self.provider.get_translation(text_wraped) for text_wraped in text_list)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: generator raised StopIteration