mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 10:22:55 +00:00
add script for automated machine translations
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
da408415a3
commit
7cf693f589
1 changed files with 30 additions and 0 deletions
30
scripts/genpo.py
Executable file
30
scripts/genpo.py
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/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))
|
Loading…
Add table
Reference in a new issue