I want to translate an English text like (final_str = 'Example') into German, does somebody have an example which I can build into my code and modify it?
Asked
Active
Viewed 367 times
0
-
1There is a module called "translate", you can check [this](https://www.tutorialspoint.com/python_text_processing/python_text_translation.htm#:~:text=Text%20translation%20from%20one%20language,provides%20translation%20for%20major%20languages.) out – Praveen Sep 27 '20 at 13:57
-
@Praveen now I got an Error: `ImportError: cannot import name 'etree'` – Ben Sep 27 '20 at 14:07
-
Is there any other modules you are trying to import? – Praveen Sep 27 '20 at 14:11
-
@Praveen no, I even tested it in a separate file and got the same error. – Ben Sep 27 '20 at 14:16
-
try it in console just the code i which is in the link, if you are getting the same error then, then try uninstaling and installing the module again – Praveen Sep 27 '20 at 14:45
-
@Praveen in console everythink works fine, but in pycharm not, i don't get it, now i have two errors `ImportError: cannot import name 'etree' from 'lxml' (C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\lxml\__init__.py)` – Ben Sep 27 '20 at 19:41
-
You can see [this](https://stackoverflow.com/questions/53406638/importerror-cannot-import-name-etree-on-python-3-6) question, you have to just uninstall lxml and install it again, do it by using the command "pip uninstall lxml" – Praveen Sep 28 '20 at 03:46
-
@Praveen it doesn´t work, but now googletrans workes. thanks for your help :D – Ben Sep 28 '20 at 17:09
1 Answers
0
If you mean the module googletrans you have a tutorial in the doc. In your case a quick example would be:
import googletrans
translator = googletrans.Translator()
translator.translate('Example', dest='de').text

Memristor
- 599
- 4
- 11