initial translations support
This commit is contained in:
parent
811d7b51b9
commit
ba8bd12123
18 changed files with 503 additions and 43 deletions
|
@ -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
35
lib/translate.js
Normal 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);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue