From 5ba9a0eb3fb07c252cc88a6e254ccd23966eeec6 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Thu, 19 Jan 2017 16:55:57 +0900 Subject: [PATCH] Fix empty extra node help content issue --- red/runtime/nodes/registry/loader.js | 4 +++- .../red/runtime/nodes/registry/loader_spec.js | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/red/runtime/nodes/registry/loader.js b/red/runtime/nodes/registry/loader.js index dd4292c23..9917a0532 100644 --- a/red/runtime/nodes/registry/loader.js +++ b/red/runtime/nodes/registry/loader.js @@ -381,8 +381,10 @@ function getNodeHelp(node,lang) { } if (help) { node.help[lang] = help; + } else if (lang === runtime.i18n.defaultLang) { + return null; } else { - node.help[lang] = node.help[runtime.i18n.defaultLang]; + node.help[lang] = getNodeHelp(node, runtime.i18n.defaultLang); } } return node.help[lang]; diff --git a/test/red/runtime/nodes/registry/loader_spec.js b/test/red/runtime/nodes/registry/loader_spec.js index 39b25d55e..c3df70bd5 100644 --- a/test/red/runtime/nodes/registry/loader_spec.js +++ b/test/red/runtime/nodes/registry/loader_spec.js @@ -564,6 +564,27 @@ describe("red/nodes/registry/loader",function() { loader.getNodeHelp(node,"fr").should.eql("foo"); fs.readFileSync.calledOnce.should.be.true(); }); + it("loads help, defaulting to en-US content for extra nodes", function() { + stubs.push(sinon.stub(fs,"readFileSync", function(path) { + if (path.indexOf("en-US") >= 0) { + return 'bar'; + } + throw new Error("not found"); + })); + var node = { + template: "/tmp/node/directory/file.html", + help:{} + }; + delete node.help['en-US']; + + loader.getNodeHelp(node,"fr").should.eql("bar"); + node.help['fr'].should.eql("bar"); + fs.readFileSync.calledTwice.should.be.true(); + fs.readFileSync.firstCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/fr/file.html")); + fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/en-US/file.html")); + loader.getNodeHelp(node,"fr").should.eql("bar"); + fs.readFileSync.calledTwice.should.be.true(); + }); }); });