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

Initialize list of supported languages from directories in the locale folder.

This commit is contained in:
Allen Boone 2015-06-01 13:59:25 -04:00 committed by Nick O'Leary
parent 965c0937ac
commit 284d7e26d1

View File

@ -20,6 +20,7 @@ var path = require("path");
var fs = require("fs");
var defaultLang = "en-US";
var supportedLangs = null;
var resourceMap = {
"runtime": {
@ -42,6 +43,19 @@ function registerMessageCatalog(namespace,dir,file) {
});
}
var initSupportedLangs = function() {
return when.promise(function(resolve,reject) {
fs.readdir(resourceMap.editor.basedir, function(err,files) {
if(err) {
reject(err);
} else {
supportedLangs = files;
resolve();
}
});
});
}
var MessageFileLoader = {
fetchOne: function(lng, ns, callback) {
if (resourceMap[ns]) {
@ -79,7 +93,9 @@ function init() {
},
fallbackLng: ['en-US']
},function() {
resolve();
initSupportedLangs().then(function() {
resolve();
});
});
});
}
@ -104,13 +120,12 @@ function getCatalog(namespace,lang) {
function determineLangFromHeaders(acceptedLanguages){
var lang = "en-US";
var supportedLanguages = ['en-US', 'es', 'fr', 'it', 'de', 'pt-BR', 'zh', 'zh-TW', 'ko', 'ja', 'zz-ZZ']; // TODO: pull this value from settings
for (var i=0;i<acceptedLanguages.length;i++){
if (supportedLanguages.indexOf(acceptedLanguages[i]) !== -1){
if (supportedLangs.indexOf(acceptedLanguages[i]) !== -1){
lang = acceptedLanguages[i];
break;
// check the language without the country code
} else if (supportedLanguages.indexOf(acceptedLanguages[i].split("-")[0]) !== -1) {
} else if (supportedLangs.indexOf(acceptedLangs[i].split("-")[0]) !== -1) {
lang = acceptedLanguages[i].split("-")[0];
break;
}