Skip to content

Instantly share code, notes, and snippets.

@d-demirci
Created May 28, 2020 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-demirci/f84110931d8b8af4867169e97581af60 to your computer and use it in GitHub Desktop.
Save d-demirci/f84110931d8b8af4867169e97581af60 to your computer and use it in GitHub Desktop.
translate po file using google translator with python
#!/usr/env/bin python
from googletrans import Translator
import polib
translator = Translator(service_urls=[
'translate.google.com',
'translate.google.co.kr',
])
#source file
po = polib.pofile('django.po')
for entry in po.untranslated_entries():
result = translator.translate(entry.msgid, dest='tr')
new_entry = polib.POEntry(
msgid=entry.msgid,
msgstr=result.text,
occurrences=entry.occurrences )
po.append(new_entry)
#save as new file
po.save('newfile.po')
#deal with duplicates later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment