auto-detect doesn't work when translating from zh_CN to en
Allianzcortex opened this issue · 9 comments
Awesome Job ! This project really helps me a lot ! But maybe there is a small issue about language auto-detect when translating from zh_CN to en.
Based on the document , if you want to translate a sentence from en to zh_CN , you just need to use three lines:
In [1]: from translate import Translator
In [2]: translator= Translator(to_lang="zh")
In [3]: translation = translator.translate("This is a pen.")
Out [3]: 这是一支笔
So based on my understanding , if you want to implement the reversed action, you also need three lines:
In [1]: from translate import Translator
In [2]: translator= Translator(to_lang="en")
In [3]: translation = translator.translate("这是一支笔")
Out [3]: 这是一支笔 # Still the original sentence. translation doesn't work
But if you specify the input language,it will work:
In [1]: from translate import Translator
In [2]: translator= Translator(from_lang="zh_CN",to_lang="en")
In [3]: translation = translator.translate("这是一支笔")
Out [3]: This is a pen # Translate successfully
Below is the screenshot tested on python3.5:
Same issue too. Please fix, Thanks.
Same issue ~ Please fix, Thanks.
This problem is on https://mymemory.translated.net. We are investigating to fix this problem.
Anybody can confirm if this is recovered?
This is because there is a default value 'en' for from_lang. As a result, auto-detect does not work. Check out the following codes.
class Translator:
def __init__(self, to_lang, from_lang='en', provider=None, secret_access_key=None, **kwargs):
How do you translate "学而时习之“ from English to English?
Quick fix:
from translate import Translator
translator= Translator(from_lang="zh", to_lang="en")
translation = translator.translate("这是一支笔")
'This is a pen' #Output
Hope it helps !
Quick fix:
from translate import Translator translator= Translator(from_lang="zh", to_lang="en") translation = translator.translate("这是一支笔") 'This is a pen' #Output
Hope it helps !
In this case, however, auto-detect cannot work at all.
Quick fix:
from translate import Translator translator= Translator(from_lang="zh", to_lang="en") translation = translator.translate("这是一支笔") 'This is a pen' #Output
Hope it helps !
In this case, however, auto-detect cannot work at all.
There you have it !
from langdetect import detect
from translate import Translator
def translate(sentence):
lang_detected = detect(sentence)
print(lang_detected)
translator= Translator(from_lang=lang_detected, to_lang="en")
translation = translator.translate(sentence)
return translation
translate('"这是一支笔"')
# zh-cn
# 'This is a pen'
I was going to share the same solution as yours @terrosdesigns 😁
I hope they can add langdetect
as a dependency to this project, this way, we can make MyMemory
's Translation API do less work and focus on "Translation" rather than "Language Detection". 😊