From 7e8f5a312b3f70f7de292366051400b3c7f00f73 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Fri, 5 Feb 2010 15:40:31 +0000 Subject: [PATCH] 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 --- editor/svgcanvas.js | 12 ++++++++++ extensions/ext-arrows.js | 2 +- extras/tojson.py | 52 ++++++++++++++++++++++++++++++++++++++++ extras/topo.py | 39 ++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 extras/tojson.py create mode 100644 extras/topo.py diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index ea6484f5..6eb4a47e 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -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("")); diff --git a/extensions/ext-arrows.js b/extensions/ext-arrows.js index 4b935074..62a33251 100644 --- a/extensions/ext-arrows.js +++ b/extensions/ext-arrows.js @@ -180,4 +180,4 @@ $(function() { } }; }); -}); \ No newline at end of file +}); diff --git a/extras/tojson.py b/extras/tojson.py new file mode 100644 index 00000000..5feea1d1 --- /dev/null +++ b/extras/tojson.py @@ -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) \ No newline at end of file diff --git a/extras/topo.py b/extras/topo.py new file mode 100644 index 00000000..592cbee8 --- /dev/null +++ b/extras/topo.py @@ -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() \ No newline at end of file