Merge remote-tracking branch 'upstream/master'

This commit is contained in:
witzig 2017-03-04 18:38:44 +01:00
commit d9c1d8e595
18 changed files with 501 additions and 43 deletions

View file

@ -148,7 +148,7 @@ function createMailer(callback) {
let level = args.shift();
args.shift();
args.unshift('Mail');
log[level].apply(log, args);
log[level](...args);
};
if (configItems.mailTransport === 'smtp' || !configItems.mailTransport) {

35
lib/translate.js Normal file
View file

@ -0,0 +1,35 @@
'use strict';
const config = require('config');
const Gettext = require('node-gettext');
const gt = new Gettext();
const fs = require('fs');
const path = require('path');
const log = require('npmlog');
const gettextParser = require('gettext-parser');
const language = config.language || 'en';
[].concat(config.language || []).forEach(lang => {
let data;
let file = path.join(__dirname, '..', 'languages', lang + '.mo');
try {
data = gettextParser.mo.parse(fs.readFileSync(file));
} catch (E) {
// ignore
}
if (data) {
gt.addTranslations(lang, lang, data);
gt.setTextDomain(lang);
gt.setLocale(lang);
log.info('LANG', 'Loaded language file for %s', lang);
}
});
module.exports._ = str => {
if (typeof str !== 'string') {
str = String(str);
}
return gt.dgettext(language, str);
};