mailtrain/server/lib/translate.js

51 lines
962 B
JavaScript
Raw Normal View History

2017-03-04 16:15:16 +00:00
'use strict';
const config = require('config');
const i18n = require("i18next");
const Backend = require("i18next-node-fs-backend");
2017-03-04 16:15:16 +00:00
const path = require('path');
i18n
.use(Backend)
// .use(Cache)
.init({
lng: config.language,
wait: true, // globally set to wait for loaded translations in translate hoc
// have a common namespace used around the full app
ns: ['common'],
defaultNS: 'common',
debug: true,
backend: {
loadPath: path.join(__dirname, 'locales/{{lng}}/{{ns}}.json')
}
})
function tLog(key, args) {
if (!args) {
args = {};
2017-03-04 16:15:16 +00:00
}
2017-03-07 14:30:56 +00:00
return JSON.stringify([key, args]);
}
function tUI(key, lang, args) {
if (!args) {
args = {};
2017-03-07 14:30:56 +00:00
}
return i18n.t(key, { ...args, defaultValue, lng: lang });
}
function tMark(key) {
return key;
}
module.exports.tLog = tLog;
module.exports.tUI = tUI;
module.exports.tMark = tMark;