pythonlanguage-translation

Text is not translated when I use translate Lib in Python


When I use translate Lib in Python to translate text it returns the same text without translation

from translate import Translator
translator= Translator(to_lang="en")
res = translator.translate("C'est la vie")
print(res)

the returned value is the same

C'est la vie


Solution

  • You missed a key argument in Translator(), and that is from_lang =. Here is your corrected code with the translation.

    from translate import Translator
    translator = Translator(from_lang="fr", to_lang="en")
    res = translator.translate("C'est la vie")
    print(res)
    
    
    That's life