refactoring locales management
This commit is contained in:
@@ -272,12 +272,9 @@ const eventController = {
|
||||
// return created event to the client
|
||||
res.json(event)
|
||||
|
||||
// send notification (mastodon/email)
|
||||
// only if user is authenticated
|
||||
if (req.user && !event.recurrent) {
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Create', event.id)
|
||||
}
|
||||
// send notifications (mastodon / email)
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Create', event.id)
|
||||
} catch (e) {
|
||||
res.sendStatus(400)
|
||||
debug(e)
|
||||
|
||||
@@ -11,6 +11,7 @@ const generateKeyPair = util.promisify(crypto.generateKeyPair)
|
||||
|
||||
const defaultSettings = {
|
||||
instance_timezone: 'Europe/Rome',
|
||||
instance_locale: 'en',
|
||||
instance_name: config.title.toLowerCase().replace(/ /g, ''),
|
||||
allow_registration: true,
|
||||
allow_anon_event: true,
|
||||
|
||||
@@ -100,7 +100,7 @@ const userController = {
|
||||
const user = await User.create(req.body)
|
||||
debug(`Sending registration email to ${user.email}`)
|
||||
mail.send(user.email, 'register', { user, config }, req.settings.locale)
|
||||
mail.send(config.admin_email, 'admin_register', { user, config }, req.settings.locale)
|
||||
mail.send(config.admin_email, 'admin_register', { user, config })
|
||||
res.sendStatus(200)
|
||||
} catch (e) {
|
||||
res.status(404).json(e)
|
||||
|
||||
@@ -2,12 +2,13 @@ const Email = require('email-templates')
|
||||
const path = require('path')
|
||||
const moment = require('moment-timezone')
|
||||
const config = require('config')
|
||||
const settings = require('./controller/settings')
|
||||
const settingsController = require('./controller/settings')
|
||||
const debug = require('debug')('email')
|
||||
const { Task, TaskManager } = require('../taskManager')
|
||||
const locales = require('../../locales')
|
||||
|
||||
const mail = {
|
||||
send (addresses, template, locals, locale) {
|
||||
send (addresses, template, locals, locale = settingsController.settings.instance_locale) {
|
||||
const task = new Task({
|
||||
name: 'MAIL',
|
||||
removable: true,
|
||||
@@ -17,8 +18,8 @@ const mail = {
|
||||
TaskManager.add(task)
|
||||
},
|
||||
|
||||
_send (addresses, template, locales, locale) {
|
||||
debug(`Send ${template} email to ${addresses}`)
|
||||
_send (addresses, template, locals, locale) {
|
||||
debug(`Send ${template} email to ${addresses} with locale ${locale}`)
|
||||
const email = new Email({
|
||||
views: { root: path.join(__dirname, '..', 'emails') },
|
||||
htmlToText: true,
|
||||
@@ -38,12 +39,13 @@ const mail = {
|
||||
objectNotation: true,
|
||||
syncFiles: false,
|
||||
updateFiles: false,
|
||||
defaultLocale: settings.locale,
|
||||
locale: settings.locale,
|
||||
locales: ['it', 'es', 'en', 'ca']
|
||||
defaultLocale: settingsController.settings.instance_locale || 'en',
|
||||
locale,
|
||||
locales: Object.keys(locales)
|
||||
},
|
||||
transport: config.smtp
|
||||
})
|
||||
|
||||
const msg = {
|
||||
template,
|
||||
message: {
|
||||
@@ -51,10 +53,10 @@ const mail = {
|
||||
bcc: config.admin_email
|
||||
},
|
||||
locals: {
|
||||
...locales,
|
||||
...locals,
|
||||
locale,
|
||||
config: { title: config.title, baseurl: config.baseurl, description: config.description, admin_email: config.admin_email },
|
||||
datetime: datetime => moment.unix(datetime).format('ddd, D MMMM HH:mm')
|
||||
datetime: datetime => moment.unix(datetime).locale(locale).format('ddd, D MMMM HH:mm')
|
||||
}
|
||||
}
|
||||
return email.send(msg)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const config = require('config')
|
||||
const moment = require('moment-timezone')
|
||||
const settingsController = require('../controller/settings')
|
||||
// const debug = require('debug')('event:modals')
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
@@ -39,7 +40,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
Event.belongsTo(models.event, { as: 'parent' })
|
||||
}
|
||||
|
||||
Event.prototype.toNoteAP = function (username, follower = []) {
|
||||
Event.prototype.toNoteAP = function (username, locale, follower = []) {
|
||||
const tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, '_'))
|
||||
const tag_links = tags.map(t => {
|
||||
return `<a href='/tags/${t}' class='mention hashtag status-link' rel='tag'><span>#${t}</span></a>`
|
||||
@@ -47,8 +48,8 @@ module.exports = (sequelize, DataTypes) => {
|
||||
|
||||
const content = `<a href='${config.baseurl}/event/${this.id}'>${this.title}</a><br/>
|
||||
📍 ${this.place.name}<br/>
|
||||
📅 ${moment.unix(this.start_datetime).format('dddd, D MMMM (HH:mm)')}<br/><br/>
|
||||
${this.description.length > 300 ? this.description.substr(0, 300) + '...' : this.description}<br/>
|
||||
📅 ${moment.unix(this.start_datetime).locale(locale).format('dddd, D MMMM (HH:mm)')}<br/><br/>
|
||||
${this.description.length > 500 ? this.description.substr(0, 500) + '...' : this.description}<br/>
|
||||
${tag_links} <br/>`
|
||||
|
||||
const attachment = []
|
||||
|
||||
Reference in New Issue
Block a user