libreoffice-online/loleaflet/util/po2json.py
Andras Timar 3d80e2a263 Write translation to json, even when translation is the same as original string
A bug was found: Slide was translated to Slide in pt_BR, while Slide was
translated to Diapositivo in pt. The identical translation was ignored,
and browser fell back to pt translation, which was wrong in pt_BR UI.
2016-07-07 22:53:48 +02:00

45 lines
1,009 B
Python
Executable file

#!/usr/bin/python
#
# convert .po to .json
#
import json
import optparse
import os
import polib
import re
import string
import sys
parser = optparse.OptionParser(usage="usage: %prog [options] pofile...")
parser.add_option("--quiet", action="store_false", default=True, dest="verbose", help="don't print status messages to stdout")
(options, args) = parser.parse_args()
if args == None or len(args) == 0:
print("ERROR: you must specify at least one po file to translate");
sys.exit(1)
paramFix = re.compile("(\\(([0-9])\\))")
for srcfile in args:
destfile = os.path.splitext(srcfile)[0] + ".json"
if options.verbose:
print("INFO: converting %s to %s" % (srcfile, destfile))
xlate_map = {}
po = polib.pofile(srcfile, autodetect_encoding=False, encoding="utf-8", wrapwidth=-1)
for entry in po.translated_entries():
if entry.msgstr == '':
continue
xlate_map[entry.msgid] = entry.msgstr;
dest = open(destfile, "w")
dest.write(json.dumps(xlate_map, sort_keys = True));
dest.close()