summaryrefslogtreecommitdiff
path: root/googletranslate.py
blob: e21f5474a25571212a3b9a66b31c78c87833b107 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python

import polib
from googletrans import Translator
from time import sleep

ttl=Translator()
po=polib.pofile('in.po')
cnt=0
print "Current progress: "+str(po.percent_translated())+"%"
print "Initiating"

for e in po.untranslated_entries():
    if not "#" in e.msgid and not "%%" in e.msgid:
        cnt+=1
        try:
            e.msgstr=ttl.translate(str(e.msgid), src='en', dest='pt_BR').text
        except:
            pass
        sleep(0.25)
        print "%s\n-> %s" % (e.msgid, e.msgstr)
        if (cnt % 20) == 0:
            po.save()
            sleep(1) # Safety timer
            print "\033[33;1mSaved Successfully\033[0m"

po.save()
print "Translated %d entries" % cnt
print "Progress afterwards:"+str(po.percent_translated())+"%"