translating external files type thing
Dan Stromberg
drsalists at gmail.com
Tue Apr 13 16:02:54 EDT 2021
Hi.
Does this give you any ideas?
#!/usr/bin/env python3
"""Quick translation program - English to Icelandic."""
# import pprint
import googletrans
# pprint.pprint(googletrans.LANGUAGES)
translator = googletrans.Translator()
with open('input-file', 'r') as file_:
english_text = file_.read()
translated = translator.translate(english_text, src='en', dest='is')
with open('output-file', 'w') as file_:
file_.write(translated.text)
My input-file contains:
This is a test of the emergency broadcast system.
I like the music of Björk.
HTH.
On Tue, Apr 13, 2021 at 12:16 PM Quentin Bock <qberz2005 at gmail.com> wrote:
> okay, so I'm making a translating program, and I have files set to be
> translated (they're in Icelandic) and I want all of them to be read in
> English but I'm not sure how to open the files and translate them at the
> same time. I'm also not even sure how to translate an external file
> to English from another language.
> I can't show code for this because I don't know if it's possible to do what
> I'm asking.
> Hopefully, this question is understandable
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list