From 043b8a31058b81796673b02b78da2692d6b7bcc6 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 23 Nov 2015 14:14:55 +0000 Subject: [PATCH] Register node message catalog directly, not via event --- red/runtime/nodes/registry/loader.js | 8 -------- red/runtime/nodes/registry/localfilesystem.js | 8 +++----- .../nodes/registry/localfilesystem_spec.js | 16 ++++++++-------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/red/runtime/nodes/registry/loader.js b/red/runtime/nodes/registry/loader.js index 3a3d8a2d2..d5ee05986 100644 --- a/red/runtime/nodes/registry/loader.js +++ b/red/runtime/nodes/registry/loader.js @@ -26,18 +26,10 @@ var RED; var settings; var runtime; -function registerMessageCatalog(info) { - runtime.i18n.registerMessageCatalog(info.namespace,info.dir,info.file); -} - function init(_runtime) { runtime = _runtime; settings = runtime.settings; localfilesystem.init(runtime); - if (runtime.events) { - runtime.events.removeListener("node-locales-dir", registerMessageCatalog); - runtime.events.on("node-locales-dir", registerMessageCatalog); - } RED = require('../../../red'); } diff --git a/red/runtime/nodes/registry/localfilesystem.js b/red/runtime/nodes/registry/localfilesystem.js index 7cf2c5e6b..36a9bd88c 100644 --- a/red/runtime/nodes/registry/localfilesystem.js +++ b/red/runtime/nodes/registry/localfilesystem.js @@ -20,6 +20,7 @@ var path = require("path"); var events; var log; +var i18n; var settings; var defaultNodesDir = path.resolve(path.join(__dirname,"..","..","..","..","nodes")); @@ -29,6 +30,7 @@ function init(runtime,_defaultNodesDir,_disableNodePathScan) { settings = runtime.settings; events = runtime.events; log = runtime.log; + i18n = runtime.i18n; if (_disableNodePathScan) { disableNodePathScan = _disableNodePathScan; @@ -204,11 +206,7 @@ function getNodeFiles(_defaultNodesDir,disableNodePathScan) { //console.log(nodeFiles); var defaultLocalesPath = path.resolve(path.join(defaultNodesDir,"core","locales")); - events.emit("node-locales-dir", { - namespace:"node-red", - dir: defaultLocalesPath, - file: "messages.json" - }); + i18n.registerMessageCatalog("node-red",defaultLocalesPath,"messages.json"); if (settings.userDir) { dir = path.join(settings.userDir,"nodes"); diff --git a/test/red/runtime/nodes/registry/localfilesystem_spec.js b/test/red/runtime/nodes/registry/localfilesystem_spec.js index aa0c864aa..7e5a9812f 100644 --- a/test/red/runtime/nodes/registry/localfilesystem_spec.js +++ b/test/red/runtime/nodes/registry/localfilesystem_spec.js @@ -45,7 +45,7 @@ describe("red/nodes/registry/localfilesystem",function() { } describe("#getNodeFiles",function() { it("Finds all the node files in the resources tree",function(done) { - localfilesystem.init({events:{emit:function(){}},settings:{}}); + localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}}); var nodeList = localfilesystem.getNodeFiles(resourcesDir,true); nodeList.should.have.a.property("node-red"); var nm = nodeList['node-red']; @@ -56,7 +56,7 @@ describe("red/nodes/registry/localfilesystem",function() { done(); }); it("Excludes node files from settings",function(done) { - localfilesystem.init({events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js']}}); + localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesExcludes:['TestNode1.js']}}); var nodeList = localfilesystem.getNodeFiles(resourcesDir,true); nodeList.should.have.a.property("node-red"); var nm = nodeList['node-red']; @@ -66,7 +66,7 @@ describe("red/nodes/registry/localfilesystem",function() { done(); }); it("Finds nodes in userDir/nodes",function(done) { - localfilesystem.init({events:{emit:function(){}},settings:{userDir:userDir}}); + localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{userDir:userDir}}); var nodeList = localfilesystem.getNodeFiles(__dirname,true); nodeList.should.have.a.property("node-red"); var nm = nodeList['node-red']; @@ -77,7 +77,7 @@ describe("red/nodes/registry/localfilesystem",function() { }); it("Finds nodes in settings.nodesDir (string)",function(done) { - localfilesystem.init({events:{emit:function(){}},settings:{nodesDir:userDir}}); + localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:userDir}}); var nodeList = localfilesystem.getNodeFiles(__dirname,true); nodeList.should.have.a.property("node-red"); var nm = nodeList['node-red']; @@ -87,7 +87,7 @@ describe("red/nodes/registry/localfilesystem",function() { done(); }); it("Finds nodes in settings.nodesDir (array)",function(done) { - localfilesystem.init({events:{emit:function(){}},settings:{nodesDir:[userDir]}}); + localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{nodesDir:[userDir]}}); var nodeList = localfilesystem.getNodeFiles(__dirname,true); nodeList.should.have.a.property("node-red"); var nm = nodeList['node-red']; @@ -106,7 +106,7 @@ describe("red/nodes/registry/localfilesystem",function() { } return _join.apply(null,arguments); })); - localfilesystem.init({events:{emit:function(){}},settings:{}}); + localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}}); var nodeList = localfilesystem.getNodeFiles(moduleDir,false); nodeList.should.have.a.property("node-red"); var nm = nodeList['node-red']; @@ -141,7 +141,7 @@ describe("red/nodes/registry/localfilesystem",function() { } return _join.apply(null,arguments); })); - localfilesystem.init({events:{emit:function(){}},settings:{}},moduleDir,true); + localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}},moduleDir,true); var nodeModule = localfilesystem.getModuleFiles('TestNodeModule'); nodeModule.should.have.a.property('TestNodeModule'); nodeModule['TestNodeModule'].should.have.a.property('name','TestNodeModule'); @@ -165,7 +165,7 @@ describe("red/nodes/registry/localfilesystem",function() { } return _join.apply(null,arguments); })); - localfilesystem.init({events:{emit:function(){}},settings:{}},moduleDir,true); + localfilesystem.init({i18n:{registerMessageCatalog:function(){}},events:{emit:function(){}},settings:{}},moduleDir,true); /*jshint immed: false */ (function(){ localfilesystem.getModuleFiles('WontExistModule');