mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
30 lines
700 B
Python
30 lines
700 B
Python
![]() |
#!/usr/bin/python
|
||
|
|
||
|
from googletrans import Translator
|
||
|
import sys
|
||
|
|
||
|
if len(sys.argv) < 3:
|
||
|
print('usage: <POT> <language>')
|
||
|
sys.exit(1)
|
||
|
|
||
|
potfile = sys.argv[1]
|
||
|
language = sys.argv[2]
|
||
|
|
||
|
with open(potfile, 'r') as f:
|
||
|
content = f.read()
|
||
|
|
||
|
translator = Translator()
|
||
|
newcontent = []
|
||
|
for line in content.splitlines():
|
||
|
if line.startswith('msgid "'):
|
||
|
msgid = line.replace('msgid "', '')
|
||
|
msgid = msgid[:-1]
|
||
|
if msgid:
|
||
|
msgid = translator.translate(msgid, dest=language).text
|
||
|
newcontent.append(line)
|
||
|
elif line.startswith('msgstr "'):
|
||
|
newcontent.append('msgstr "%s"' % msgid)
|
||
|
else:
|
||
|
newcontent.append(line)
|
||
|
|
||
|
print('\n'.join(newcontent))
|