mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Allow editor language to be chosen in editor settings
This gets stored in localStorage of the browser which is not ideal. This is because we load language catalogs before we load user preferences - so if this was stored in the runtime, the editor wouldn't know the user's preference until it was too late to apply it. This is likely good enough for now - may need to do something more convoluted later on.
This commit is contained in:
32
packages/node_modules/@node-red/util/lib/i18n.js
vendored
32
packages/node_modules/@node-red/util/lib/i18n.js
vendored
@@ -50,10 +50,21 @@ function registerMessageCatalogs(catalogs) {
|
||||
function registerMessageCatalog(namespace,dir,file) {
|
||||
return initPromise.then(function() {
|
||||
return new Promise((resolve,reject) => {
|
||||
resourceMap[namespace] = { basedir:dir, file:file};
|
||||
i18n.loadNamespaces(namespace,function() {
|
||||
resolve();
|
||||
});
|
||||
resourceMap[namespace] = { basedir:dir, file:file, lngs: []};
|
||||
fs.readdir(dir,function(err, files) {
|
||||
if (err) {
|
||||
resolve();
|
||||
} else {
|
||||
files.forEach(function(f) {
|
||||
if (fs.existsSync(path.join(dir,f,file))) {
|
||||
resourceMap[namespace].lngs.push(f);
|
||||
}
|
||||
});
|
||||
i18n.loadNamespaces(namespace,function() {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -163,11 +174,24 @@ function getCatalog(namespace,lang) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of languages a given catalog is available in.
|
||||
* @name availableLanguages
|
||||
* @function
|
||||
* @memberof @node-red/util_i18n
|
||||
*/
|
||||
function availableLanguages(namespace) {
|
||||
if (resourceMap.hasOwnProperty(namespace)) {
|
||||
return resourceMap[namespace].lngs
|
||||
}
|
||||
}
|
||||
|
||||
var obj = module.exports = {
|
||||
init: init,
|
||||
registerMessageCatalog: registerMessageCatalog,
|
||||
registerMessageCatalogs: registerMessageCatalogs,
|
||||
catalog: getCatalog,
|
||||
availableLanguages: availableLanguages,
|
||||
/**
|
||||
* The underlying i18n library for when direct access is really needed
|
||||
*/
|
||||
|
Reference in New Issue
Block a user