diff --git a/Gruntfile.js b/Gruntfile.js index a732a18b4..d06c68080 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -93,6 +93,7 @@ module.exports = function(grunt) { // Ensure editor source files are concatenated in // the right order "editor/js/main.js", + "editor/js/i18n.js", "editor/js/settings.js", "editor/js/user.js", "editor/js/comms.js", diff --git a/editor/js/i18n.js b/editor/js/i18n.js new file mode 100644 index 000000000..de97aff58 --- /dev/null +++ b/editor/js/i18n.js @@ -0,0 +1,44 @@ +/** + * Copyright 2013, 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +RED.i18n = (function() { + + return { + init: function(done) { + i18n.init({ + resGetPath: 'locales/__ns__?lang=__lng__', + dynamicLoad: false, + ns: { + namespaces: ["editor","node-red"], + defaultNs: "editor" + }, + fallbackLng: ['en'] + },function() { + done(); + }); + RED["_"] = function() { + return i18n.t.apply(null,arguments); + } + + }, + loadCatalog: function(namespace,done) { + i18n.loadNamespace(namespace,done); + } + } +})(); + + + diff --git a/editor/js/main.js b/editor/js/main.js index 4a184ae5f..7712fa840 100644 --- a/editor/js/main.js +++ b/editor/js/main.js @@ -16,10 +16,10 @@ var RED = (function() { - function loadSettings() { - RED.settings.init(loadNodeList); + function loadLocales() { + RED.i18n.init(loadEditor); } - + function loadNodeList() { $.ajax({ headers: { @@ -29,7 +29,23 @@ var RED = (function() { url: 'nodes', success: function(data) { RED.nodes.setNodeList(data); - loadNodes(); + + var nsCount = 0; + for(var i=0;i
').appendTo("#dialog-form"); prepareEditDialog(node,node._def,"node-input"); - - - - - + $("#dialog").i18n(); $( "#dialog" ).dialog("option","title","Edit "+type+" node").dialog( "open" ); } @@ -603,6 +611,21 @@ RED.editor = (function() { } $("#dialog-config-form").html($("script[data-template-name='"+type+"']").html()); + + var ns; + if (node_def.set.module === "node-red") { + ns = "node-red"; + } else { + ns = node_def.set.id; + } + $("#dialog-config-form").find('[data-i18n]').each(function() { + var current = $(this).attr("data-i18n"); + if (current.indexOf(":") === -1) { + $(this).attr("data-i18n",ns+":"+current); + } + }); + + prepareEditDialog(configNode,node_def,"node-config-input"); var buttons = $( "#node-config-dialog" ).dialog("option","buttons"); @@ -652,6 +675,8 @@ RED.editor = (function() { } $( "#node-config-dialog" ).dialog("option","buttons",buttons); + $("#node-config-dialog").i18n(); + $( "#node-config-dialog" ) .dialog("option","node-adding",adding) .dialog("option","node-property",name) diff --git a/editor/templates/index.mst b/editor/templates/index.mst index 261df2ad3..e7cb7d489 100644 --- a/editor/templates/index.mst +++ b/editor/templates/index.mst @@ -152,7 +152,7 @@