Add scripts to convert between our language json files and po format (Issue 416)
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1344 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
52
extras/tojson.py
Normal file
52
extras/tojson.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import sys, json, codecs
|
||||
infile = codecs.open(sys.argv[1], "r", "utf-8")
|
||||
outfile = codecs.open(sys.argv[1][:-3], "w", "utf-8")
|
||||
indata = infile.readlines()
|
||||
look = False
|
||||
out = "[\n"
|
||||
js = []
|
||||
jss = ""
|
||||
|
||||
def readfrompos(pos):
|
||||
global out
|
||||
global js
|
||||
|
||||
if (indata[pos].startswith("#, -x-svg-edit-title")) or (indata[pos].startswith("#, -x-svg-edit-textContent")):
|
||||
out += '{'
|
||||
out += '"id": '
|
||||
out += " ".join(indata[pos+1].split()[1:]) + ", "
|
||||
out += '"' + line[15:].strip() + '": '
|
||||
out += " ".join(indata[pos+2].split()[1:])
|
||||
out += '}'
|
||||
elif (indata[pos].startswith("#, -x-svg-edit-both")):
|
||||
out += '{'
|
||||
out += '"id": '
|
||||
out += " ".join(indata[pos+1].split()[1:]) + ", "
|
||||
out += '"textContent": '
|
||||
out += '"' + " ".join(indata[pos+2].split()[1:]).split('|')[1] + ', '
|
||||
out += '"title": '
|
||||
out += " ".join(indata[pos+2].split()[1:]).split('|')[0] + '"'
|
||||
out += '}'
|
||||
elif (indata[pos].startswith("#, -x-svg-edit-js_strings")):
|
||||
js.append((" ".join(indata[pos+1].split()[1:]), " ".join(indata[pos+2].split()[1:])))
|
||||
|
||||
for pos, line in enumerate(indata):
|
||||
if (not look) and (line.startswith('# ---')):
|
||||
look = True
|
||||
marker = pos
|
||||
elif (look) and (line.startswith('#, -x-svg-edit')):
|
||||
readfrompos(pos)
|
||||
|
||||
js.sort()
|
||||
|
||||
for j in js:
|
||||
jss += " %s: %s,\n" % (j[0], j[1])
|
||||
|
||||
out += '{\n "js_strings": {\n'
|
||||
out += str(jss)
|
||||
out += ' "": ""\n }'
|
||||
out += "\n}"
|
||||
out += "\n]"
|
||||
out = out.replace('}{', '},\n{')
|
||||
|
||||
outfile.write(out)
|
||||
39
extras/topo.py
Normal file
39
extras/topo.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import sys, json, codecs
|
||||
infile = json.load(codecs.open(sys.argv[1], "r", "utf-8"))
|
||||
outfile = codecs.open(sys.argv[1] + ".po", "w", "utf-8")
|
||||
out = []
|
||||
|
||||
out.append("""# LANGUAGE FILE FOR SVG-EDIT, AUTOGENERATED BY TOPO.PY
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Content-Type: text/plain; charset=utf-8\\n"
|
||||
"Content-Transfer-Encoding: 8bit\\n"
|
||||
|
||||
# ---
|
||||
|
||||
""")
|
||||
|
||||
def printstr(flag, i, s):
|
||||
out.append('\n')
|
||||
if flag == '-x-svg-edit-both':
|
||||
out.append("# Enter the title first, then the contents, seperated by a pipe char (|)\n")
|
||||
out.append("#, " + flag + '\n')
|
||||
out.append("msgid \"" + i + "\"" + '\n')
|
||||
out.append("msgstr \"" + s.replace('\n', '\\n') + "\"" + '\n')
|
||||
|
||||
for line in infile:
|
||||
if line.has_key('title') and line.has_key('textContent'):
|
||||
printstr('-x-svg-edit-both', line['id'], "|".join(((line['title'], line['textContent']))))
|
||||
elif line.has_key('title'):
|
||||
printstr('-x-svg-edit-title', line['id'], line['title'])
|
||||
elif line.has_key('textContent'):
|
||||
printstr('-x-svg-edit-textContent', line['id'], line['textContent'])
|
||||
elif line.has_key('js_strings'):
|
||||
for i, s in line['js_strings'].items():
|
||||
printstr('-x-svg-edit-js_strings', i, s)
|
||||
else:
|
||||
pass # The line wasn't really a string
|
||||
|
||||
outfile.writelines(out)
|
||||
outfile.close()
|
||||
Reference in New Issue
Block a user