work-in-progress commit for #4655

This commit is contained in:
Julian Lam
2016-05-16 10:32:28 -04:00
parent 81bbe93640
commit 437770538c
7 changed files with 91 additions and 34 deletions

View File

@@ -219,26 +219,23 @@ module.exports = function(Plugins) {
fallbackMap = {};
utils.walk(pathToFolder, function(err, languages) {
var arr = [];
async.each(languages, function(pathToLang, next) {
fs.readFile(pathToLang, function(err, file) {
if (err) {
return next(err);
}
var json;
var data;
var route = pathToLang.replace(pathToFolder + '/', '');
try {
json = JSON.parse(file.toString());
data = JSON.parse(file.toString());
} catch (err) {
winston.error('[plugins] Unable to parse custom language file: ' + pathToLang + '\r\n' + err.stack);
return next(err);
}
arr.push({
file: json,
route: pathToLang.replace(pathToFolder, '')
});
Plugins.customLanguages[route] = Plugins.customLanguages[route] || {};
_.extendOwn(Plugins.customLanguages[route], data);
if (pluginData.defaultLang && pathToLang.endsWith(pluginData.defaultLang + '/' + path.basename(pathToLang))) {
fallbackMap[path.basename(pathToLang, '.json')] = path.join(pathToFolder, pluginData.defaultLang, path.basename(pathToLang));
@@ -251,7 +248,7 @@ module.exports = function(Plugins) {
return callback(err);
}
Plugins.customLanguages = Plugins.customLanguages.concat(arr);
// do I need this either?
_.extendOwn(Plugins.customLanguageFallbacks, fallbackMap);
callback();