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:
parent
965c0937ac
commit
284d7e26d1
21
red/i18n.js
21
red/i18n.js
@ -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,9 +93,11 @@ function init() {
|
||||
},
|
||||
fallbackLng: ['en-US']
|
||||
},function() {
|
||||
initSupportedLangs().then(function() {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getCatalog(namespace,lang) {
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user