From 1dd9984521174c145f8f8da062d44a3b4bd93fb6 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 23 Nov 2015 13:55:17 +0000 Subject: [PATCH] Pickup default language from i18n module --- red/runtime/nodes/registry/loader.js | 4 +-- .../red/runtime/nodes/registry/loader_spec.js | 26 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/red/runtime/nodes/registry/loader.js b/red/runtime/nodes/registry/loader.js index 9b3149074..3a3d8a2d2 100644 --- a/red/runtime/nodes/registry/loader.js +++ b/red/runtime/nodes/registry/loader.js @@ -172,7 +172,7 @@ function loadNodeConfig(fileInfo) { index = regExp.lastIndex; var help = content.substring(regExp.lastIndex-match[1].length,regExp.lastIndex); - var lang = "en-US"; + var lang = runtime.i18n.defaultLang; if ((match = langRegExp.exec(help)) !== null) { lang = match[1]; } @@ -332,7 +332,7 @@ function getNodeHelp(node,lang) { if (help) { node.help[lang] = help; } else { - node.help[lang] = node.help["en-US"]; + node.help[lang] = node.help[runtime.i18n.defaultLang]; } } diff --git a/test/red/runtime/nodes/registry/loader_spec.js b/test/red/runtime/nodes/registry/loader_spec.js index 18e9e6ee5..43887dc5c 100644 --- a/test/red/runtime/nodes/registry/loader_spec.js +++ b/test/red/runtime/nodes/registry/loader_spec.js @@ -44,7 +44,7 @@ describe("red/nodes/registry/loader",function() { }) describe("#init",function() { it("init",function() { - loader.init({events:{on:function(){},removeListener:function(){}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}}}); localfilesystem.init.called.should.be.true; }); }); @@ -53,7 +53,7 @@ describe("red/nodes/registry/loader",function() { it("load empty set without settings available", function(done) { stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};})); stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};})); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}}); loader.load("foo",true).then(function() { localfilesystem.getNodeFiles.called.should.be.true; localfilesystem.getNodeFiles.lastCall.args[0].should.eql('foo'); @@ -65,7 +65,7 @@ describe("red/nodes/registry/loader",function() { it("load empty set with settings available triggers registery save", function(done) { stubs.push(sinon.stub(localfilesystem,"getNodeFiles", function(){ return {};})); stubs.push(sinon.stub(registry,"saveNodeList", function(){ return {};})); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.load("foo",true).then(function() { registry.saveNodeList.called.should.be.true; done(); @@ -96,7 +96,7 @@ describe("red/nodes/registry/loader",function() { stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(nodes,"registerType")); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.load().then(function(result) { registry.addNodeSet.called.should.be.true; registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode1"); @@ -143,7 +143,7 @@ describe("red/nodes/registry/loader",function() { // This module isn't already loaded stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(nodes,"registerType")); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.load().then(function(result) { registry.addNodeSet.called.should.be.true; registry.addNodeSet.lastCall.args[0].should.eql("node-red/MultipleNodes1"); @@ -194,7 +194,7 @@ describe("red/nodes/registry/loader",function() { stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(nodes,"registerType")); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.load().then(function(result) { registry.addNodeSet.called.should.be.true; registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode2"); @@ -243,7 +243,7 @@ describe("red/nodes/registry/loader",function() { stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(nodes,"registerType")); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.load().then(function(result) { registry.addNodeSet.called.should.be.true; registry.addNodeSet.lastCall.args[0].should.eql("node-red/TestNode3"); @@ -290,7 +290,7 @@ describe("red/nodes/registry/loader",function() { stubs.push(sinon.stub(registry,"getNodeInfo", function(){ return null; })); stubs.push(sinon.stub(nodes,"registerType")); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.load().then(function(result) { registry.addNodeSet.called.should.be.true; registry.addNodeSet.lastCall.args[0].should.eql("node-red/DoesNotExist"); @@ -317,7 +317,7 @@ describe("red/nodes/registry/loader",function() { describe("#addModule",function() { it("throws error if settings unavailable", function() { - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return false;}}}); /*jshint immed: false */ (function(){ loader.addModule("test-module"); @@ -326,7 +326,7 @@ describe("red/nodes/registry/loader",function() { it("returns rejected error if module already loaded", function(done) { stubs.push(sinon.stub(registry,"getModuleInfo",function(){return{}})); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.addModule("test-module").otherwise(function(err) { err.code.should.eql("module_already_loaded"); @@ -338,7 +338,7 @@ describe("red/nodes/registry/loader",function() { stubs.push(sinon.stub(localfilesystem,"getModuleFiles",function() { throw new Error("failure"); })); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.addModule("test-module").otherwise(function(err) { err.message.should.eql("failure"); done(); @@ -370,7 +370,7 @@ describe("red/nodes/registry/loader",function() { stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" })); stubs.push(sinon.stub(registry,"addNodeSet", function(){ return })); stubs.push(sinon.stub(nodes,"registerType")); - loader.init({events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},settings:{available:function(){return true;}}}); loader.addModule("TestNodeModule").then(function(result) { result.should.eql("a node list"); registry.addNodeSet.calledOnce.should.be.true; @@ -420,7 +420,7 @@ describe("red/nodes/registry/loader",function() { stubs.push(sinon.stub(registry,"saveNodeList", function(){ return "a node list" })); stubs.push(sinon.stub(registry,"addNodeSet", function(){ return })); stubs.push(sinon.stub(nodes,"registerType")); - loader.init({events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}}); + loader.init({i18n:{defaultLang:"en-US"},events:{on:function(){},removeListener:function(){}},version: function() { return "0.12.0"}, settings:{available:function(){return true;}}}); loader.addModule("TestNodeModule").then(function(result) { result.should.eql("a node list"); registry.addNodeSet.called.should.be.false;