mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Add scripts/reconvert_l10n.py to convert l10n back
This commit is contained in:
parent
11b3d1eb80
commit
cea0cdae8f
32
scripts/reconvert_l10n.py
Normal file
32
scripts/reconvert_l10n.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import json
|
||||||
|
import polib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
JSON_KEY_TRANSL="translated strings"
|
||||||
|
JSON_KEY_OR="or"
|
||||||
|
JSON_KEY_TR="tr"
|
||||||
|
JSON_KEY_CO="context"
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
po = polib.pofile(open(sys.argv[1]).read())
|
||||||
|
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,
|
||||||
|
open(sys.argv[1] + '.json', 'w'),
|
||||||
|
ensure_ascii=False,
|
||||||
|
indent="\t",
|
||||||
|
separators=(',', ': '),
|
||||||
|
sort_keys=True,
|
||||||
|
)
|
Loading…
Reference in a new issue