Merge pull request #1122 from CANDY-LINE/feature/i18n-issue

Fix empty extra node help content issue
This commit is contained in:
Nick O'Leary 2017-03-01 16:38:08 +00:00 committed by GitHub
commit 571b9fb8e0
2 changed files with 42 additions and 1 deletions

View File

@ -393,8 +393,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];

View File

@ -564,6 +564,45 @@ 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();
});
it("fails to load en-US help content", function() {
stubs.push(sinon.stub(fs,"readFileSync", function(path) {
throw new Error("not found");
}));
var node = {
template: "/tmp/node/directory/file.html",
help:{}
};
delete node.help['en-US'];
should.not.exist(loader.getNodeHelp(node,"en-US"));
should.not.exist(node.help['en-US']);
fs.readFileSync.calledTwice.should.be.true();
fs.readFileSync.firstCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/en-US/file.html"));
fs.readFileSync.lastCall.args[0].should.eql(path.normalize("/tmp/node/directory/locales/en/file.html"));
should.not.exist(loader.getNodeHelp(node,"en-US"));
fs.readFileSync.callCount.should.eql(4);
});
});
});