Created
May 28, 2020 10:16
-
-
Save d-demirci/f84110931d8b8af4867169e97581af60 to your computer and use it in GitHub Desktop.
translate po file using google translator with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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