Move i18n class into another module

parent b077396e
const enLocale = require('./locale/en.json');
module.exports = function(){
let _locale = 'en';
this._ = function(str) {
return _locale == 'en' ? enLocale[str] || str : str;
}
this.setLocale = function(locale) {
_locale = locale;
}
this.getLocale = function() {
return _locale;
}
return this;
};
......@@ -7,7 +7,7 @@ const Canvas = require('canvas');
const Image = Canvas.Image;
const app = express();
const config = require('./config.json');
const enLocale = require('./locale/en.json');
const i18n = require('./i18n.js')();
app.set('x-powered-by', false);
app.set('view engine', 'pug');
......@@ -154,24 +154,6 @@ app.get('/generate.png', function (req, res) {
})
});
let i18n = (function(){
let _locale = 'en';
this._ = function(str) {
return _locale == 'en' ? enLocale[str] || str : str;
}
this.setLocale = function(locale) {
_locale = locale;
}
this.getLocale = function() {
return _locale;
}
return this;
})();
app.get('/', function(req, res) {
let locale = req.headers['accept-language'] || '';
i18n.setLocale(locale.indexOf('en') !== -1 && locale.indexOf('en') < locale.indexOf('fr') ? 'en' : 'fr');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment