i18n in server. Some fixes

This commit is contained in:
vjrj 2017-12-09 17:54:18 +01:00
parent 23ec2b8f55
commit a0e5dc4723
13 changed files with 543 additions and 121 deletions

View file

@ -1,3 +1,79 @@
import { Meteor } from 'meteor/meteor';
import nodemailer from 'nodemailer';
import { MailTime } from 'meteor/ostrio:mailer';
import i18n from 'i18next';
if (Meteor.isDevelopment) process.env.MAIL_URL = Meteor.settings.private.MAIL_URL;
// console.log(i18n.t('Inicio del mailer'));
const transports = [];
// First transport
const fstTransport = nodemailer.createTransport(Meteor.settings.private.MAIL_URL);
transports.push(fstTransport);
// console.log(fstTransport.options.auth.user);
const db = Meteor.users.rawDatabase(); // new Mongo.Collection('__mailTimeQueue__').rawDatabase();
// Use __mailTimeQueue collection in any db
// db.getCollection("__mailTimeQueue__").count()
// https://litmus.com/community/discussions/4633-is-there-a-reliable-1px-horizontal-rule-method
const hr = `<table cellspacing="0" cellpadding="0" border="0" width="100%" style="width: 100% !important;">
<tr>
<td align="left" valign="top" width="600px" height="1" style="background-color: #f0f0f0; border-collapse:collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; mso-line-height-rule: exactly; line-height: 1px;"><!--[if gte mso 15]>&nbsp;<![endif]--></td>
</tr>
</table>`;
const MailQueue = new MailTime({
db,
type: 'server',
strategy: 'balancer', // Transports will be used in round robin chain
transports,
from(transport) {
// To pass spam-filters `from` field should be correctly set
// for each transport, check `transport` object for more options
return `"${i18n.t('AppName')}" <${transport.options.auth.user}>`;
},
debug: true,
concatEmails: true, // Concatenate emails to the same addressee
concatSubject: `${i18n.t('Nuevas notificaciones de {{app}}', { app: i18n.t('AppName') })}`,
/* eslint-disable */
concatDelimiter: hr + '<h2>{{{subject}}}</h2>', // Start each concatenated email with it's own subject
/* eslint-enable */
// concatThrottling: 30,
template: MailTime.Template // Use default template
});
// A Client (not used yet)
// const MailQueueClient = new MailTime({
// db,
// type: 'client',
// debug: true,
// strategy: 'balancer', // Transports will be used in round robin chain
// concatEmails: true // Concatenate emails to the same address
// });
export default function sendMail(opts, debug) {
if (debug) {
MailQueue.sendMail(opts, (err, info) => { if (err) { console.error(err); } else { console.log(info); } });
} else {
MailQueue.sendMail(opts);
}
}
if (Meteor.settings.private.testMailer) {
const emailOpts = {
to: Meteor.settings.private.testEmail,
userName: 'someone',
sendAt: new Date(),
subject: 'Some new notification',
text: 'Plain text message',
template: '<body>{{appName}}<h2>{{{subject}}}</h2>{{{html}}}</body>',
appName: i18n.t('AppName'),
html: '<p>Styled message</p>'
};
sendMail(emailOpts, true);
sendMail(emailOpts, true);
sendMail(emailOpts, true);
sendMail(emailOpts, true);
}

View file

@ -0,0 +1,31 @@
import { Meteor } from 'meteor/meteor';
import i18n from 'i18next';
import backend from 'i18next-sync-fs-backend';
import i18nOpts from '../common/i18n';
// import moment from 'moment';
// import { T9n } from 'meteor-accounts-t9n';
i18nOpts.backend.loadPath = `${Meteor.absolutePath}/public${i18nOpts.backend.loadPath}`;
i18nOpts.backend.addPath = `${Meteor.absolutePath}/public${i18nOpts.backend.addPath}`;
// console.log(i18nOpts.backend.loadPath);
i18nOpts.debug = false;
i18nOpts.saveMissing = true;
i18nOpts.initImmediate = false;
i18n
.use(backend)
.init(i18nOpts, (err) => {
if (err) {
console.error(err);
}
});
/* export function setUserLang (lng) {
* moment.locale(lng);
* T9n.setLanguage(lng);
* } */
// console.log(i18n.t('Servidor arrancado'));
export default i18n;

View file

@ -1,3 +1,4 @@
import './i18n';
import './accounts';
import './api';
import './fixtures';