Begin locale revamp (will break all non-en languages for now)

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1894 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-12-31 20:02:35 +00:00
parent dea45ccdfa
commit 0bc65d35c6
3 changed files with 461 additions and 25 deletions

219
editor/locale/lang.test.js Normal file
View File

@ -0,0 +1,219 @@
({
common: {
"ok": 'OK',
"cancel": 'Cancel',
"key_backspace": "backspace",
"key_del": "delete",
"key_down": "down",
"key_up": "up",
"layer": "Layer"
},
misc: {
"copyrightLabel": "Powered by"
},
ui: {
"toggle_stroke_tools": "Show/hide more stroke tools",
"palette": "Click to change fill color, shift-click to change stroke color",
"zoom_panel": "Change zoom level"
},
properties: {
"idLabel": "Identify the element",
"fill_color": "Change fill color",
"stroke_color": "Change stroke color",
"stroke_style": "Change stroke dash style",
"stroke_width": "Change stroke width by 1, shift-click to change by 0.1",
"selected_x": "Change X coordinate",
"selected_y": "Change Y coordinate",
"linecap_butt": "Linecap: Butt",
"linecap_round": "Linecap: Round",
"linecap_square": "Linecap: Square",
"linejoin_bevel": "Linejoin: Bevel",
"linejoin_miter": "Linejoin: Miter",
"linejoin_round": "Linejoin: Round",
"tool_angle": "Change rotation angle",
"tool_blur": "Change gaussian blur value",
"tool_opacity": "Change selected item opacity",
"circle_cx": "Change circle's cx coordinate",
"circle_cy": "Change circle's cy coordinate",
"circle_r": "Change circle's radius",
"ellipse_cx": "Change ellipse's cx coordinate",
"ellipse_cy": "Change ellipse's cy coordinate",
"ellipse_rx": "Change ellipse's x radius",
"ellipse_ry": "Change ellipse's y radius",
"line_x1": "Change line's starting x coordinate",
"line_x2": "Change line's ending x coordinate",
"line_y1": "Change line's starting y coordinate",
"line_y2": "Change line's ending y coordinate",
"rect_height_tool": "Change rectangle height",
"rect_width_tool": "Change rectangle width",
"cornerRadiusLabel": "Change Rectangle Corner Radius",
"image_width": "Change image width",
"image_height": "Change image height",
"image_url": "Change URL",
"path_node_x": "Change node's x coordinate",
"path_node_y": "Change node's y coordinate",
"seg_type": "Change Segment type",
"straight_segments": "Straight",
"curve_segments": "Curve",
"text": "Change text contents",
"font_family": "Change Font Family",
"tool_font_size": "Change Font Size",
"tool_bold": "Bold Text",
"tool_italic": "Italic Text"
},
tools: {
"main_icon": "Main Menu",
"bkgnd_color": "Change background color/opacity",
"connector_no_arrow": "No arrow",
"fitToContent": "Fit to Content",
"fit_to_all": "Fit to all content",
"fit_to_canvas": "Fit to canvas",
"fit_to_layer_content": "Fit to layer content",
"fit_to_sel": "Fit to selection",
"align_relative_to": "Align relative to ...",
"relativeToLabel": "relative to:",
"page": "page",
"largest_object": "largest object",
"selected_objects": "selected objects",
"smallest_object": "smallest object",
"tool_clear": "New Image",
"tool_open": "Open Image",
"tool_export": "Export as PNG",
"tool_save": "Save Image",
"tool_position": "Align Element to Page",
"tool_alignbottom": "Align Bottom",
"tool_aligncenter": "Align Center",
"tool_alignleft": "Align Left",
"tool_alignmiddle": "Align Middle",
"tool_alignright": "Align Right",
"tool_aligntop": "Align Top",
"tool_circle": "Circle",
"tool_ellipse": "Ellipse",
"tool_fhellipse": "Free-Hand Ellipse",
"tool_fhpath": "Pencil Tool",
"tool_fhrect": "Free-Hand Rectangle",
"tool_image": "Image Tool",
"url_notice": "NOTE: This image cannot be embedded. It will depend on this path to be displayed",
"tool_line": "Line Tool",
"tool_path": "Path Tool",
"tool_select": "Select Tool",
"tool_square": "Square",
"tool_rect": "Rectangle",
"tool_text": "Text Tool",
"tool_zoom": "Zoom Tool",
"tool_undo": "Undo",
"tool_redo": "Redo",
"tool_source": "Edit Source",
"tool_wireframe": "Wireframe Mode",
"view_grid": "Show/Hide Grid",
"tool_clone": "Clone Element",
"tool_clone_multi": "Clone Elements",
"tool_delete": "Delete Element",
"tool_delete_multi": "Delete Selected Elements",
"tool_group": "Group Elements",
"tool_topath": "Convert to Path",
"tool_reorient": "Reorient path",
"tool_ungroup": "Ungroup Elements",
"tool_docprops": "Document Properties",
"tool_import": "Import SVG",
"tool_imagelib": "Image Library",
"tool_move_bottom": "Move to Bottom",
"tool_move_top": "Move to Top",
"tool_node_clone": "Clone Node",
"tool_node_delete": "Delete Node",
"tool_node_link": "Link Control Points",
"tool_add_subpath": "Add sub-path",
"tool_openclose_path": "Open/close sub-path",
"tool_source_save": "Apply Changes",
"tool_eyedropper": "Eye Dropper Tool",
"mode_connect": "Connect two objects"
},
layers: {
"layersLabel": "Layers:",
"layer_delete": "Delete Layer",
"layer_down": "Move Layer Down",
"layer_new": "New Layer",
"layer_rename": "Rename Layer",
"layer_up": "Move Layer Up",
"selLayerLabel": "Move elements to:",
"selLayerNames": "Move selected elements to a different layer",
"sidepanel_handle": "L a y e r s", // "title": "Drag left/right to resize side panel"},
},
config: {
"svginfo_image_props": "Image Properties",
"svginfo_title": "Title",
"svginfo_dim": "Canvas Dimensions",
"svginfo_width": "Width:",
"svginfo_height": "Height:",
"svginfo_editor_prefs": "Editor Preferences",
"svginfo_icons": "Icon size",
"svginfo_lang": "Language",
"svginfo_change_background": "Editor Background",
"svginfo_bg_note": "Note: Background will not be saved with image.",
"icon_large": "Large",
"icon_medium": "Medium",
"icon_small": "Small",
"icon_xlarge": "Extra Large",
"selectedPredefined": "Select predefined:",
"includedImages": "Included Images",
"image_opt_embed": "Embed data (local files)",
"image_opt_ref": "Use file reference"
},
notification: {
"invalidAttrValGiven":"Invalid value given",
"noContentToFitTo":"No content to fit to",
"layer":"Layer",
"dupeLayerName":"There is already a layer named that!",
"enterUniqueLayerName":"Please enter a unique layer name",
"enterNewLayerName":"Please enter the new layer name",
"layerHasThatName":"Layer already has that name",
"QmoveElemsToLayer":"Move selected elements to layer \"%s\"?",
"QwantToClear":"Do you want to clear the drawing?\nThis will also erase your undo history!",
"QwantToOpen":"Do you want to open a new file?\nThis will also erase your undo history!",
"QerrorsRevertToSource":"There were parsing errors in your SVG source.\nRevert back to original SVG source?",
"QignoreSourceChanges":"Ignore changes made to SVG source?",
"featNotSupported":"Feature not supported",
"enterNewImgURL":"Enter the new image URL",
"defsFailOnSave": "NOTE: Due to a bug in your browser, this image may appear wrong (missing gradients or elements). It will however appear correct once actually saved.",
"loadingImage":"Loading image, please wait...",
"saveFromBrowser": "Select \"Save As...\" in your browser to save this image as a %s file.",
"noteTheseIssues": "Also note the following issues: ",
"unsavedChanges": "There are unsaved changes.",
"enterNewLinkURL": "Enter the new hyperlink URL",
"errorLoadingSVG": "Error: Unable to load SVG data",
"URLloadFail": "Unable to load from URL",
"ok":"OK",
"cancel":"Cancel",
"key_up":"Up",
"key_down":"Down",
"key_backspace":"Backspace",
"key_del":"Del"
}
})

View File

@ -9,6 +9,42 @@
*/
var svgEditor = (function($, Editor) {
function setStrings(type, obj, ids) {
// Root element to look for element from
var parent = $('#svg_editor').parent();
for(var sel in obj) {
var val = obj[sel];
if(!val) console.log(sel);
if(ids) sel = '#' + sel;
var $elem = parent.find(sel);
if($elem.length) {
var elem = parent.find(sel)[0];
switch ( type ) {
case 'content':
for(var i = 0; i < elem.childNodes.length; i++) {
var node = elem.childNodes[i];
if(node.nodeType === 3 && node.textContent.replace(/\s/g,'')) {
node.textContent = '!!!' + val;
break;
}
}
break;
case 'title':
elem.title = '!!!' + val;
break;
}
} else {
console.log('Missing: ' + sel);
}
}
}
Editor.putLocale = function(given_param, good_langs){
var lang_param;
@ -25,13 +61,16 @@ var svgEditor = (function($, Editor) {
return;
}
console.log(lang_param)
// Set to English if language is not in list of good langs
if($.inArray(lang_param, good_langs) == -1) {
if($.inArray(lang_param, good_langs) == -1 && lang_param !== 'test') {
lang_param = "en";
}
// don't bother on first run if language is English
if(lang_param.indexOf("en") == 0) return;
}
var conf = Editor.curConfig;
@ -40,33 +79,207 @@ var svgEditor = (function($, Editor) {
var processFile = function(data){
if(!data) return;
var LangData = eval(data), js_strings;
var more = Editor.canvas.runExtensions("addLangData", lang_param, true);
var langData = eval(data);
var more = Editor.canvas.runExtensions("addlangData", lang_param, true);
$.each(more, function(i, m) {
if(m.data) {
LangData = $.merge(LangData, m.data);
langData = $.merge(langData, m.data);
}
});
$.each(LangData, function(i, data) {
if(data.id) {
var elem = $('#svg_editor').parent().find('#'+data.id)[0];
if(elem) {
if(data.title)
elem.title = data.title;
if(data.textContent) {
// Only replace non-empty text nodes, not elements
$.each(elem.childNodes, function(j, node) {
if(node.nodeType == 3 && $.trim(node.textContent)) {
node.textContent = data.textContent;
}
});
}
}
} else if(data.js_strings) {
js_strings = data.js_strings;
// Old locale file, do nothing for now.
if(!langData.tools) return;
var tools = langData.tools,
misc = langData.misc,
properties = langData.properties,
config = langData.config,
layers = langData.layers,
common = langData.common,
ui = langData.ui;
setStrings('content', {
connector_no_arrow: tools.connector_no_arrow,
copyrightLabel: misc.copyrightLabel,
curve_segments: properties.curve_segments,
fitToContent: tools.fitToContent,
fit_to_all: tools.fit_to_all,
fit_to_canvas: tools.fit_to_canvas,
fit_to_layer_content: tools.fit_to_layer_content,
fit_to_sel: tools.fit_to_sel,
icon_large: config.icon_large,
icon_medium: config.icon_medium,
icon_small: config.icon_small,
icon_xlarge: config.icon_xlarge,
image_opt_embed: config.image_opt_embed,
image_opt_ref: config.image_opt_ref,
includedImages: config.includedImages,
largest_object: tools.largest_object,
layersLabel: layers.layersLabel,
page: tools.page,
relativeToLabel: tools.relativeToLabel,
selLayerLabel: layers.selLayerLabel,
selectedPredefined: config.selectedPredefined,
selected_objects: tools.selected_objects,
smallest_object: tools.smallest_object,
straight_segments: properties.straight_segments,
svginfo_bg_note: config.svginfo_bg_note,
svginfo_change_background: config.svginfo_change_background,
svginfo_dim: config.svginfo_dim,
svginfo_editor_prefs: config.svginfo_editor_prefs,
svginfo_height: config.svginfo_height,
svginfo_icons: config.svginfo_icons,
svginfo_image_props: config.svginfo_image_props,
svginfo_lang: config.svginfo_lang,
svginfo_title: config.svginfo_title,
svginfo_width: config.svginfo_width,
tool_docprops_cancel: common.cancel,
tool_docprops_save: common.ok,
tool_source_cancel: common.cancel,
tool_source_save: common.ok,
sidepanel_handle: layers.sidepanel_handle,
tool_clear: tools.tool_clear,
tool_docprops: tools.tool_docprops,
tool_export: tools.tool_export,
tool_import: tools.tool_import,
tool_imagelib: tools.tool_imagelib,
tool_open: tools.tool_open,
tool_save: tools.tool_save
}, true);
setStrings('title', {
align_relative_to: tools.align_relative_to,
bkgnd_color: tools.bkgnd_color,
circle_cx: properties.circle_cx,
circle_cy: properties.circle_cy,
circle_r: properties.circle_r,
cornerRadiusLabel: properties.cornerRadiusLabel,
ellipse_cx: properties.ellipse_cx,
ellipse_cy: properties.ellipse_cy,
ellipse_rx: properties.ellipse_rx,
ellipse_ry: properties.ellipse_ry,
fill_color: properties.fill_color,
font_family: properties.font_family,
idLabel: properties.idLabel,
image_height: properties.image_height,
image_url: properties.image_url,
image_width: properties.image_width,
layer_delete: layers.layer_delete,
layer_down: layers.layer_down,
layer_new: layers.layer_new,
layer_rename: layers.layer_rename,
layer_up: layers.layer_up,
line_x1: properties.line_x1,
line_x2: properties.line_x2,
line_y1: properties.line_y1,
line_y2: properties.line_y2,
linecap_butt: properties.linecap_butt,
linecap_round: properties.linecap_round,
linecap_square: properties.linecap_square,
linejoin_bevel: properties.linejoin_bevel,
linejoin_miter: properties.linejoin_miter,
linejoin_round: properties.linejoin_round,
main_icon: tools.main_icon,
mode_connect: tools.mode_connect,
palette: ui.palette,
zoom_panel: ui.zoom_panel,
path_node_x: properties.path_node_x,
path_node_y: properties.path_node_y,
rect_height_tool: properties.rect_height_tool,
rect_width_tool: properties.rect_width_tool,
seg_type: properties.seg_type,
selLayerNames: layers.selLayerNames,
selected_x: properties.selected_x,
selected_y: properties.selected_y,
stroke_color: properties.stroke_color,
stroke_style: properties.stroke_style,
stroke_width: properties.stroke_width,
svginfo_title: config.svginfo_title,
text: properties.text,
toggle_stroke_tools: ui.toggle_stroke_tools,
tool_add_subpath: tools.tool_add_subpath,
tool_alignbottom: tools.tool_alignbottom,
tool_aligncenter: tools.tool_aligncenter,
tool_alignleft: tools.tool_alignleft,
tool_alignmiddle: tools.tool_alignmiddle,
tool_alignright: tools.tool_alignright,
tool_aligntop: tools.tool_aligntop,
tool_angle: properties.tool_angle,
tool_blur: properties.tool_blur,
tool_bold: properties.tool_bold,
tool_circle: tools.tool_circle,
tool_clone: tools.tool_clone,
tool_clone_multi: tools.tool_clone_multi,
tool_delete: tools.tool_delete,
tool_delete_multi: tools.tool_delete_multi,
tool_ellipse: tools.tool_ellipse,
tool_eyedropper: tools.tool_eyedropper,
tool_fhellipse: tools.tool_fhellipse,
tool_fhpath: tools.tool_fhpath,
tool_fhrect: tools.tool_fhrect,
tool_font_size: properties.tool_font_size,
tool_group: tools.tool_group,
tool_image: tools.tool_image,
tool_italic: properties.tool_italic,
tool_line: tools.tool_line,
tool_move_bottom: tools.tool_move_bottom,
tool_move_top: tools.tool_move_top,
tool_node_clone: tools.tool_node_clone,
tool_node_delete: tools.tool_node_delete,
tool_node_link: tools.tool_node_link,
tool_opacity: properties.tool_opacity,
tool_openclose_path: tools.tool_openclose_path,
tool_path: tools.tool_path,
tool_position: tools.tool_position,
tool_rect: tools.tool_rect,
tool_redo: tools.tool_redo,
tool_reorient: tools.tool_reorient,
tool_select: tools.tool_select,
tool_source: tools.tool_source,
tool_square: tools.tool_square,
tool_text: tools.tool_text,
tool_topath: tools.tool_topath,
tool_undo: tools.tool_undo,
tool_ungroup: tools.tool_ungroup,
tool_wireframe: tools.tool_wireframe,
tool_view_grid: tools.view_grid,
tool_zoom: tools.tool_zoom,
url_notice: tools.url_notice
}
});
Editor.setLang(lang_param, js_strings);
, true);
Editor.setLang(lang_param, langData);
// $.each(langData, function(i, data) {
// if(data.id) {
// var elem = $('#svg_editor').parent().find('#'+data.id)[0];
// if(elem) {
// if(data.title)
// elem.title = data.title;
// if(data.textContent) {
// // Only replace non-empty text nodes, not elements
// $.each(elem.childNodes, function(j, node) {
// if(node.nodeType == 3 && $.trim(node.textContent)) {
// node.textContent = data.textContent;
// }
// });
// }
// }
// } else if(data.js_strings) {
// js_strings = data.js_strings;
// }
// });
}
$.ajax({
@ -83,3 +296,4 @@ var svgEditor = (function($, Editor) {
return Editor;
}(jQuery, svgEditor));

View File

@ -4559,10 +4559,13 @@
});
Editor.setLang = function(lang, strings) {
Editor.setLang = function(lang, allStrings) {
$.pref('lang', lang);
$('#lang_select').val(lang);
if(strings) {
if(allStrings) {
var strings = allStrings.notification;
// $.extend will only replace the given strings
var oldLayerName = $('#layerlist tr.layersel td.layername').text();
var rename_layer = (oldLayerName == uiStrings.layer + ' 1');