summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-04-22 18:46:04 -0400
committerFrederic Guillot <fred@kanboard.net>2015-04-22 18:46:04 -0400
commitb5163c483c88914ac17e94e275871996f12fc210 (patch)
treebf8cbacf2f260e423d0c08d39fa6b3ed7d777c35 /app
parentc09501497b75c3042471a3da5633f4c6b48e33e9 (diff)
Send notifications with the language of the recipient
Diffstat (limited to 'app')
-rw-r--r--app/Model/Config.php4
-rw-r--r--app/Model/Notification.php28
2 files changed, 25 insertions, 7 deletions
diff --git a/app/Model/Config.php b/app/Model/Config.php
index bbcff50c..813cc84f 100644
--- a/app/Model/Config.php
+++ b/app/Model/Config.php
@@ -117,15 +117,17 @@ class Config extends Base
'fr_FR' => 'fr',
'it_IT' => 'it',
'hu_HU' => 'hu',
+ 'nl_NL' => 'nl',
'pl_PL' => 'pl',
'pt_BR' => 'pt-br',
'ru_RU' => 'ru',
+ 'sr_Latn_RS' => 'sr',
'fi_FI' => 'fi',
'sv_SE' => 'sv',
+ 'tr_TR' => 'tr',
'zh_CN' => 'zh-cn',
'ja_JP' => 'ja',
'th_TH' => 'th',
- 'tr_TR' => 'tr',
);
$lang = $this->getCurrentLanguage();
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index 8414b121..5835de54 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -3,6 +3,7 @@
namespace Model;
use Core\Session;
+use Core\Translator;
use Swift_Message;
use Swift_Mailer;
use Swift_TransportException;
@@ -36,7 +37,7 @@ class Notification extends Base
return $this->db
->table(User::TABLE)
- ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email')
+ ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language')
->eq('notifications_enabled', '1')
->neq('email', '')
->notin(User::TABLE.'.id', $exclude_users)
@@ -45,7 +46,7 @@ class Notification extends Base
return $this->db
->table(ProjectPermission::TABLE)
- ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email')
+ ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language')
->join(User::TABLE, 'id', 'user_id')
->eq('project_id', $project_id)
->eq('notifications_enabled', '1')
@@ -110,19 +111,34 @@ class Notification extends Base
$mailer = Swift_Mailer::newInstance($this->container['mailer']);
- $message = Swift_Message::newInstance()
+ foreach ($users as $user) {
+
+ $this->container['logger']->debug('Send email notification to '.$user['username'].' lang='.$user['language']);
+
+ // Use the user language otherwise use the application language (do not use the session language)
+ if (! empty($user['language'])) {
+ Translator::load($user['language']);
+ }
+ else {
+ Translator::load($this->config->get('application_language', 'en_US'));
+ }
+
+ // Send the message
+ $message = Swift_Message::newInstance()
->setSubject($this->getMailSubject($template, $data))
->setFrom(array(MAIL_FROM => $author ?: 'Kanboard'))
- ->setBody($this->getMailContent($template, $data), 'text/html');
+ ->setBody($this->getMailContent($template, $data), 'text/html')
+ ->setTo(array($user['email'] => $user['name'] ?: $user['username']));
- foreach ($users as $user) {
- $message->setTo(array($user['email'] => $user['name'] ?: $user['username']));
$mailer->send($message);
}
}
catch (Swift_TransportException $e) {
$this->container['logger']->error($e->getMessage());
}
+
+ // Restore locales
+ $this->config->setupTranslations();
}
/**