1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #1918 from node-red-hitachi/fix-i18n-for-safari

Fix i18n handling for ja-JP locale on Safari/MacOS
This commit is contained in:
Nick O'Leary 2018-10-11 14:21:20 -07:00 committed by GitHub
commit a20eaf852f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -21,6 +21,18 @@ var i18n = require("@node-red/util").i18n; // TODO: separate module
var runtimeAPI;
function loadResource(lang, namespace) {
var catalog = i18n.i.getResourceBundle(lang, namespace);
if (!catalog) {
var parts = lang.split("-");
if (parts.length == 2) {
var new_lang = parts[0];
return i18n.i.getResourceBundle(new_lang, namespace);
}
}
return catalog;
}
module.exports = {
init: function(_runtimeAPI) {
runtimeAPI = _runtimeAPI;
@ -33,7 +45,7 @@ module.exports = {
var prevLang = i18n.i.language;
// Trigger a load from disk of the language if it is not the default
i18n.i.changeLanguage(lang, function(){
var catalog = i18n.i.getResourceBundle(lang, namespace);
var catalog = loadResource(lang, namespace);
res.json(catalog||{});
});
i18n.i.changeLanguage(prevLang);

View File

@ -91,6 +91,30 @@ describe("api/editor/locales", function() {
done();
});
});
it('returns for locale defined only with primary tag ', function(done) {
var orig = i18n.i.getResourceBundle;
i18n.i.getResourceBundle = function (lang, ns) {
if (lang === "ja-JP") {
return undefined;
}
return orig(lang, ns);
};
request(app)
// returns `ja` instead of `ja-JP`
.get("/locales/message-catalog?lng=ja-JP")
.expect(200)
.end(function(err,res) {
i18n.i.getResourceBundle = orig;
if (err) {
return done(err);
}
res.body.should.have.property('namespace','message-catalog');
res.body.should.have.property('lang','ja');
done();
});
});
});
// describe('get all node resource catalogs',function() {