mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-17 05:21:36 +03:00
be37070fb6
migration from usage of config() to just an object of config. no relevant issue - Change 'loadConfig' task to 'ensureConfig' to more accurately reflect what it is actually doing. Its sole purpose is to make sure a `config.js` file exists, and as such the name now reflects that purpose. - Update config/index.js to export the ghostConfig object directly so that it can be accessed from other modules - Update all references of config(). to config. This was a blind global find all and replace, treat it as such. - Fixes to tests to support new config access method - Allow each test to still work when invoked invidually
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
var fs = require('fs'),
|
|
config = require('../../server/config'),
|
|
/**
|
|
* Create new Polyglot object
|
|
* @type {Polyglot}
|
|
*/
|
|
I18n;
|
|
|
|
I18n = function (ghost) {
|
|
|
|
// TODO: validate
|
|
var lang = ghost.settings('defaultLang'),
|
|
path = config.paths.lang,
|
|
langFilePath = path + lang + '.json';
|
|
|
|
return function (req, res, next) {
|
|
|
|
if (lang === 'en_US') {
|
|
// TODO: do stuff here to optimise for en
|
|
|
|
// Make jslint empty block error go away
|
|
lang = 'en_US';
|
|
}
|
|
|
|
/** 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 (error) {
|
|
if (error) {
|
|
console.log('No language file found for language ' + lang + '. Defaulting to en_US');
|
|
lang = 'en_US';
|
|
}
|
|
|
|
fs.readFile(langFilePath, function (error, data) {
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
|
|
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; |