}
/** TODO potentially use req.acceptedLanguages rather than the default
* TODO handle loading language file for frontend on frontend request etc
* TODO switch this mess to be promise driven */
fs.stat(langFilePath, function (err, stat) {
if (err) {
console.log('No language file found for language ' + lang + '. Defaulting to en');
lang = 'en';
}
fs.readFile(langFilePath, function (err, data) {
if (err) {
throw err;
}
try {
data = JSON.parse(data);
} catch (e) {
throw e; // TODO - do something better with the error here
}
ghost.polyglot().extend(data);
next();
});
});
};
};
module.exports.load = I18n;
}());
TODO: validate