Reputation: 77
I am trying a language translation code where I am using the translate
package where the provider is Microsoft. The input text has 2 languages english and Russian and my to language is english. The translated text does not change to English. Can anyone provide some inputs ?
from translate import Translator
to_lang = "en"
translator = Translator(provider='microsoft', to_lang=to_lang, secret_access_key=secret)
translator.translate("Elapsed Task Time – время в течение, которого выполнялась задача ")
'Elapsed Task Time – время в течение, которого выполнялась задача '
Here is what I tried to compare the issue
from googletrans import Translator
translator = Translator()
translator.translate(r.text, dest='en').text
"Elapsed Task Time - the time during which the task was performed"
Expected result :
"Elapsed Task Time - the time during which the task was performed"
Upvotes: 1
Views: 1054
Reputation: 1561
For whatever reason, the (older) version of the Microsoft translator API used in this library won't autodetect mixed languages properly. It will work if your mixed languages include English and you specify from_lang
for the other language. It always detects English. For example, if you specify from_lang='ru'
and translate to 'it', the English portion will also be translated to Italian.
So, back to your scenario, this should work:
translator = Translator(provider='microsoft', to_lang=to_lang, from_lang='ru', secret_access_key=secret)
That said, I recommend you look at: https://github.com/MicrosoftTranslator/Text-Translation-API-V3-Python. In particular, Translate.py. This should work as expected and uses the latest API (well, more precisely, you get control over which API).
Upvotes: 1