2014-05-05 14:19:07 +00:00
|
|
|
import json
|
|
|
|
import polib
|
|
|
|
|
|
|
|
JSON_KEY_TRANSL="translated strings"
|
|
|
|
JSON_KEY_OR="or"
|
|
|
|
JSON_KEY_TR="tr"
|
|
|
|
JSON_KEY_CO="context"
|
|
|
|
|
2014-06-21 17:23:27 +00:00
|
|
|
def reconvert(filename):
|
|
|
|
po = polib.pofile(open(filename, encoding='utf-8').read())
|
2014-05-05 14:19:07 +00:00
|
|
|
translations = []
|
|
|
|
|
|
|
|
for entry in po:
|
|
|
|
if entry.msgstr:
|
|
|
|
t_entry = {}
|
|
|
|
t_entry[JSON_KEY_OR] = entry.msgid
|
|
|
|
t_entry[JSON_KEY_TR] = entry.msgstr
|
|
|
|
if entry.msgctxt is not None:
|
|
|
|
t_entry[JSON_KEY_CO] = entry.msgctxt
|
|
|
|
translations.append(t_entry)
|
|
|
|
|
|
|
|
result = {JSON_KEY_TRANSL: translations}
|
|
|
|
|
|
|
|
json.dump(
|
|
|
|
result,
|
2014-06-21 17:23:27 +00:00
|
|
|
open(filename + '.json', 'w', encoding='utf-8'),
|
2014-05-05 14:19:07 +00:00
|
|
|
ensure_ascii=False,
|
|
|
|
indent="\t",
|
|
|
|
separators=(',', ': '),
|
|
|
|
sort_keys=True,
|
|
|
|
)
|
2014-06-21 17:23:27 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
for filename in sys.argv[1:]:
|
|
|
|
reconvert(filename)
|