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

Merge pull request #1743 from node-red-hitachi/0.19-allow-i18n-translation-in-runtime

Allow i18n translation in runtime
This commit is contained in:
Nick O'Leary 2018-05-30 13:20:05 +01:00 committed by GitHub
commit 4cfbf7f71c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,16 +81,32 @@ var MessageFileLoader = {
} }
function getCurrentLocale() {
var env = process.env;
for (var name of ['LC_ALL', 'LC_MESSAGES', 'LANG']) {
if (name in env) {
var val = env[name];
return val.substring(0, 2);
}
}
return undefined;
}
function init() { function init() {
return when.promise(function(resolve,reject) { return when.promise(function(resolve,reject) {
i18n.backend(MessageFileLoader); i18n.backend(MessageFileLoader);
i18n.init({ var opt = {
ns: { ns: {
namespaces: [], namespaces: [],
defaultNs: "runtime" defaultNs: "runtime"
}, },
fallbackLng: [defaultLang] fallbackLng: [defaultLang]
},function() { };
var lang = getCurrentLocale();
if (lang) {
opt.lng = lang;
}
i18n.init(opt ,function() {
resolve(); resolve();
}); });
}); });