diff --git a/editor/locale/locale.js b/editor/locale/locale.js index a5297ec5..7d8c1166 100644 --- a/editor/locale/locale.js +++ b/editor/locale/locale.js @@ -6,10 +6,9 @@ * Copyright(c) 2009 Narendra Sisodya * */ -var put_locale = function(svgCanvas, given_param){ +var put_locale = function(svgCanvas, given_param, good_langs){ var lang_param; - // TODO: Make this array be based on entries in svg-editor.html - var good_langs = ['ar','cs','de','en','es','fa','fr','fy','hi','ja','nl','ro','ru','sk','zh-TW']; + if(given_param) { lang_param = given_param; } else { @@ -28,7 +27,7 @@ var put_locale = function(svgCanvas, given_param){ if($.inArray(lang_param, good_langs) == -1) { lang_param = "en"; } - + // don't bother on first run if language is English if(lang_param.indexOf("en") == 0) return; } diff --git a/editor/svg-editor.js b/editor/svg-editor.js index adc0f77b..c278f73e 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -2907,7 +2907,11 @@ function svg_edit_setup() { // This happens when the page is loaded $(function() { svgCanvas = svg_edit_setup(); - put_locale(svgCanvas); + var good_langs = []; + $('#lang_select option').each(function() { + good_langs.push(this.value); + }); + put_locale(svgCanvas, null, good_langs); try{ json_encode = function(obj){ diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index f542087d..61d2b498 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -913,6 +913,7 @@ function BatchCommand(text) { // TODO: declare the variables and set them as null, then move this setup stuff to // an initialization function - probably just use clear() + var canvas = this, svgns = "http://www.w3.org/2000/svg", xlinkns = "http://www.w3.org/1999/xlink", @@ -937,6 +938,13 @@ function BatchCommand(text) { '').documentElement, true); $(svgroot).appendTo(container); + + var nsMap = {}; + nsMap[xlinkns] = 'xlink'; + nsMap[xmlns] = 'xmlns'; + nsMap[se_ns] = 'se'; + nsMap[htmlns] = 'xhtml'; + nsMap[mathns] = 'mathml'; var svgcontent = svgdoc.createElementNS(svgns, "svg"); $(svgcontent).attr({ @@ -1476,6 +1484,7 @@ function BatchCommand(text) { var svgToString = function(elem, indent) { var out = new Array(); + if (elem) { cleanupElement(elem); var attrs = elem.attributes, @@ -1486,15 +1495,24 @@ function BatchCommand(text) { for (var i=0; i=0; i--) { attr = attrs.item(i); @@ -1520,19 +1538,10 @@ function BatchCommand(text) { } // map various namespaces to our fixed namespace prefixes - // TODO: put this into a map and do a look-up instead of if-else - if (attr.namespaceURI == xlinkns) { - out.push('xlink:'); - } - else if(attr.namespaceURI == 'http://www.w3.org/2000/xmlns/' && attr.localName != 'xmlns') { - out.push('xmlns:'); - } - else if(attr.namespaceURI == xmlns) { - out.push('xml:'); - } - else if(attr.namespaceURI == se_ns) { - out.push('se:'); + if(attr.namespaceURI) { + out.push(nsMap[attr.namespaceURI]+':'); } + out.push(attr.localName); out.push("=\""); out.push(attrVal); out.push("\""); }