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
master
Jeff Schiller 2010-02-05 15:40:31 +00:00
parent 1021cceef8
commit 7e8f5a312b
4 changed files with 104 additions and 1 deletions

View File

@ -3521,6 +3521,18 @@ function BatchCommand(text) {
var N = points.numberOfItems;
if (N >= 4) {
// loop through every 3 points and convert to a cubic bezier curve segment
//
// NOTE: this is cheating, it means that every 3 points has the potential to
// be a corner instead of treating each point in an equal manner. In general,
// this technique does not look that good.
//
// I am open to better ideas!
//
// Reading:
// - http://www.efg2.com/Lab/Graphics/Jean-YvesQueinecBezierCurves.htm
// - http://www.codeproject.com/KB/graphics/BezierSpline.aspx?msg=2956963
// - http://www.ian-ko.com/ET_GeoWizards/UserGuide/smooth.htm
// - http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/bezier-der.html
var curpos = points.getItem(0), prevCtlPt = null;
var d = [];
d.push(["M",curpos.x,",",curpos.y," C"].join(""));

View File

@ -180,4 +180,4 @@ $(function() {
}
};
});
});
});

52
extras/tojson.py Normal file
View 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
View 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()