From cec6ceba9c7f33033db2098584268b1c8f0753a4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 May 2017 10:16:14 +0200 Subject: Use the language of the recipient not the actor Signed-off-by: Joas Schilling --- settings/Hooks.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'settings/Hooks.php') diff --git a/settings/Hooks.php b/settings/Hooks.php index 2d8b17ebfd9..c8fc9d6a8c3 100644 --- a/settings/Hooks.php +++ b/settings/Hooks.php @@ -23,11 +23,13 @@ namespace OC\Settings; use OC\Settings\Activity\Provider; use OCP\Activity\IManager as IActivityManager; +use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\L10N\IFactory; use OCP\Mail\IMailer; class Hooks { @@ -42,15 +44,28 @@ class Hooks { protected $urlGenerator; /** @var IMailer */ protected $mailer; + /** @var IConfig */ + protected $config; + /** @var IFactory */ + protected $languageFactory; /** @var IL10N */ protected $l; - public function __construct(IActivityManager $activityManager, IUserManager $userManager, IUserSession $userSession, IURLGenerator $urlGenerator, IMailer $mailer, IL10N $l) { + public function __construct(IActivityManager $activityManager, + IUserManager $userManager, + IUserSession $userSession, + IURLGenerator $urlGenerator, + IMailer $mailer, + IConfig $config, + IFactory $languageFactory, + IL10N $l) { $this->activityManager = $activityManager; $this->userManager = $userManager; $this->userSession = $userSession; $this->urlGenerator = $urlGenerator; $this->mailer = $mailer; + $this->config = $config; + $this->languageFactory = $languageFactory; $this->l = $l; } @@ -77,6 +92,14 @@ class Hooks { $actor = $this->userSession->getUser(); if ($actor instanceof IUser) { if ($actor->getUID() !== $user->getUID()) { + $this->l = $this->languageFactory->get( + 'settings', + $this->config->getUserValue( + $user->getUID(), 'core', 'lang', + $this->config->getSystemValue('default_language', 'en') + ) + ); + $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); $event->setAuthor($actor->getUID()) ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); @@ -127,6 +150,14 @@ class Hooks { $actor = $this->userSession->getUser(); if ($actor instanceof IUser) { if ($actor->getUID() !== $user->getUID()) { + $this->l = $this->languageFactory->get( + 'settings', + $this->config->getUserValue( + $user->getUID(), 'core', 'lang', + $this->config->getSystemValue('default_language', 'en') + ) + ); + $text = $this->l->t('%1$s changed your email address on %2$s.', [$actor->getDisplayName(), $instanceUrl]); $event->setAuthor($actor->getUID()) ->setSubject(Provider::EMAIL_CHANGED_BY, [$actor->getUID()]); -- cgit v1.2.3