mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch 'master' into runtime-api
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
**/
|
||||
|
||||
var i18n = require("i18next");
|
||||
|
||||
var when = require("when");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
@@ -34,9 +35,9 @@ function registerMessageCatalogs(catalogs) {
|
||||
|
||||
function registerMessageCatalog(namespace,dir,file) {
|
||||
return initPromise.then(function() {
|
||||
when.promise(function(resolve,reject) {
|
||||
return new Promise((resolve,reject) => {
|
||||
resourceMap[namespace] = { basedir:dir, file:file};
|
||||
i18n.loadNamespace(namespace,function() {
|
||||
i18n.loadNamespaces(namespace,function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@@ -56,7 +57,9 @@ function mergeCatalog(fallback,catalog) {
|
||||
}
|
||||
|
||||
var MessageFileLoader = {
|
||||
fetchOne: function(lng, ns, callback) {
|
||||
type: "backend",
|
||||
init: function(services, backendOptions, i18nextOptions) {},
|
||||
read: function(lng, ns, callback) {
|
||||
if (resourceMap[ns]) {
|
||||
var file = path.join(resourceMap[ns].basedir,lng,resourceMap[ns].file);
|
||||
//console.log(file);
|
||||
@@ -97,20 +100,27 @@ function getCurrentLocale() {
|
||||
|
||||
function init() {
|
||||
if (!initPromise) {
|
||||
initPromise = when.promise(function(resolve,reject) {
|
||||
i18n.backend(MessageFileLoader);
|
||||
// Keep this as a 'when' promise as top-level red.js uses 'otherwise'
|
||||
// and embedded users of NR may have copied that.
|
||||
initPromise = when.promise((resolve,reject) => {
|
||||
i18n.use(MessageFileLoader);
|
||||
var opt = {
|
||||
ns: {
|
||||
namespaces: [],
|
||||
defaultNs: "runtime"
|
||||
},
|
||||
fallbackLng: [defaultLang]
|
||||
// debug: true,
|
||||
defaultNS: "runtime",
|
||||
ns: [],
|
||||
fallbackLng: defaultLang,
|
||||
interpolation: {
|
||||
unescapeSuffix: 'HTML',
|
||||
escapeValue: false,
|
||||
prefix: '__',
|
||||
suffix: '__'
|
||||
}
|
||||
};
|
||||
var lang = getCurrentLocale();
|
||||
if (lang) {
|
||||
opt.lng = lang;
|
||||
}
|
||||
i18n.init(opt,function() {
|
||||
i18n.init(opt ,function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@@ -147,5 +157,6 @@ obj['_'] = function() {
|
||||
// opts.defaultValue = def;
|
||||
//}
|
||||
//console.log(arguments);
|
||||
return i18n.t.apply(null,arguments);
|
||||
var res = i18n.t.apply(i18n,arguments);
|
||||
return res;
|
||||
}
|
||||
|
Reference in New Issue
Block a user