]> source.dussan.org Git - nextcloud-server.git/commitdiff
Provide the proper language to the mailer 20513/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Tue, 31 Mar 2020 12:02:39 +0000 (14:02 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 20 Apr 2020 20:21:19 +0000 (22:21 +0200)
Else we can't properly translate the footer in the recipients e-mail
language.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/theming/lib/ThemingDefaults.php
lib/private/Mail/EMailTemplate.php
lib/private/Mail/Mailer.php
lib/private/Server.php
lib/private/Share20/Manager.php
lib/private/legacy/defaults.php
lib/public/Defaults.php
lib/public/Mail/IEMailTemplate.php
tests/Settings/Mailer/NewUserMailHelperTest.php
tests/lib/Mail/EMailTemplateTest.php
tests/lib/Mail/MailerTest.php

index 6f11f5cfa45f8e324aaa0c685b2c840e8c59b8dd..fb10d9ff342dd8c5dbdb8f4a712aff87b28cb8b9 100644 (file)
@@ -139,8 +139,8 @@ class ThemingDefaults extends \OC_Defaults {
                return $this->config->getAppValue('theming', 'url', $this->url);
        }
 
-       public function getSlogan() {
-               return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan()));
+       public function getSlogan(?string $lang = null) {
+               return \OCP\Util::sanitizeHTML($this->config->getAppValue('theming', 'slogan', parent::getSlogan($lang)));
        }
 
        public function getImprintUrl() {
index b3654f303824a1012e60d00348868ad2423ad78c..4f162e9d9ed306c6f8ac52441b676b129928474a 100644 (file)
@@ -29,8 +29,8 @@ declare(strict_types=1);
 namespace OC\Mail;
 
 use OCP\Defaults;
-use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
 use OCP\Mail\IEMailTemplate;
 
 /**
@@ -46,8 +46,8 @@ class EMailTemplate implements IEMailTemplate {
        protected $themingDefaults;
        /** @var IURLGenerator */
        protected $urlGenerator;
-       /** @var IL10N */
-       protected $l10n;
+       /** @var IFactory */
+       protected $l10nFactory;
        /** @var string */
        protected $emailId;
        /** @var array */
@@ -344,21 +344,14 @@ EOF;
 </table>
 EOF;
 
-       /**
-        * @param Defaults $themingDefaults
-        * @param IURLGenerator $urlGenerator
-        * @param IL10N $l10n
-        * @param string $emailId
-        * @param array $data
-        */
        public function __construct(Defaults $themingDefaults,
                                                                IURLGenerator $urlGenerator,
-                                                               IL10N $l10n,
+                                                               IFactory $l10nFactory,
                                                                $emailId,
                                                                array $data) {
                $this->themingDefaults = $themingDefaults;
                $this->urlGenerator = $urlGenerator;
-               $this->l10n = $l10n;
+               $this->l10nFactory = $l10nFactory;
                $this->htmlBody .= $this->head;
                $this->emailId = $emailId;
                $this->data = $data;
@@ -601,9 +594,10 @@ EOF;
         *
         * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
         */
-       public function addFooter(string $text = '') {
+       public function addFooter(string $text = '', ?string $lang = null) {
                if($text === '') {
-                       $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.');
+                       $l10n = $this->l10nFactory->get('lib', $lang);
+                       $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
                }
 
                if ($this->footerAdded) {
index 8f442365585ffdd56c7d417ec50f7b1693a0e3b3..5125a39b118a09954b5ec53c927da4d779538658 100644 (file)
@@ -32,6 +32,7 @@ use OCP\Defaults;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
 use OCP\Mail\IAttachment;
 use OCP\Mail\IEMailTemplate;
 use OCP\Mail\IMailer;
@@ -69,6 +70,8 @@ class Mailer implements IMailer {
        private $urlGenerator;
        /** @var IL10N */
        private $l10n;
+       /** @var IFactory */
+       private $l10nFactory;
 
        /**
         * @param IConfig $config
@@ -81,12 +84,14 @@ class Mailer implements IMailer {
                                                 ILogger $logger,
                                                 Defaults $defaults,
                                                 IURLGenerator $urlGenerator,
-                                                IL10N $l10n) {
+                                                IL10N $l10n,
+                                                IFactory $l10nFactory) {
                $this->config = $config;
                $this->logger = $logger;
                $this->defaults = $defaults;
                $this->urlGenerator = $urlGenerator;
                $this->l10n = $l10n;
+               $this->l10nFactory = $l10nFactory;
        }
 
        /**
@@ -144,7 +149,7 @@ class Mailer implements IMailer {
                return new EMailTemplate(
                        $this->defaults,
                        $this->urlGenerator,
-                       $this->l10n,
+                       $this->l10nFactory,
                        $emailId,
                        $data
                );
index bce4f0feaef691e58d4638b02efd6e52232339dd..9ceebf1b433bd66a1084d582e7741e82a1358eb1 100644 (file)
@@ -151,6 +151,7 @@ use OCP\IL10N;
 use OCP\IServerContainer;
 use OCP\ITempManager;
 use OCP\IUser;
+use OCP\L10N\IFactory;
 use OCP\Lock\ILockingProvider;
 use OCP\Log\ILogFactory;
 use OCP\Remote\Api\IApiFactory;
@@ -832,7 +833,8 @@ class Server extends ServerContainer implements IServerContainer {
                                $c->getLogger(),
                                $c->query(Defaults::class),
                                $c->getURLGenerator(),
-                               $c->getL10N('lib')
+                               $c->getL10N('lib'),
+                               $c->query(IFactory::class)
                        );
                });
                $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
index 1915ac952f7d17273e9c168ab62a57ba469c970c..f13878d71b4784bb47be7a7a2d8feb7829eaac9e 100644 (file)
@@ -805,9 +805,9 @@ class Manager implements IManager {
                $initiatorEmail = $initiatorUser->getEMailAddress();
                if($initiatorEmail !== null) {
                        $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]);
-                       $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : ''));
+                       $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan($l->getLanguageCode()) !== '' ? ' - ' . $this->defaults->getSlogan($l->getLanguageCode()) : ''));
                } else {
-                       $emailTemplate->addFooter();
+                       $emailTemplate->addFooter('', $l->getLanguageCode());
                }
 
                $message->useTemplate($emailTemplate);
index 8633113ba5acde24c0f71fe28576859a030c7bed..7bd083608d4f2273d63c89f017cfb4a48750cf24 100644 (file)
@@ -213,12 +213,12 @@ class OC_Defaults {
         * Returns slogan
         * @return string slogan
         */
-       public function getSlogan() {
+       public function getSlogan(?string $lang = null) {
                if ($this->themeExist('getSlogan')) {
-                       return $this->theme->getSlogan();
+                       return $this->theme->getSlogan($lang);
                } else {
                        if ($this->defaultSlogan === null) {
-                               $l10n = \OC::$server->getL10N('lib');
+                               $l10n = \OC::$server->getL10N('lib', $lang);
                                $this->defaultSlogan = $l10n->t('a safe home for all your data');
                        }
                        return $this->defaultSlogan;
index bf790bb723957ae889331beccd4d1b5a24aa49e0..c93b0f5e45549742dbf4ac11e29f00a492ad9e65 100644 (file)
@@ -135,8 +135,8 @@ class Defaults {
         * @return string
         * @since 6.0.0
         */
-       public function getSlogan() {
-               return $this->defaults->getSlogan();
+       public function getSlogan(?string $lang = null) {
+               return $this->defaults->getSlogan($lang);
        }
 
        /**
index 1c0ddbe54d42d2eab1c7491b72b07704c8ae2811..18456178ed9e19d074e7895ab8091a3c5052c8c5 100644 (file)
@@ -138,10 +138,11 @@ interface IEMailTemplate {
         * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
         *
         * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
+        * @param string $lang Optional language to set the default footer in
         *
         * @since 12.0.0
         */
-       public function addFooter(string $text = '');
+       public function addFooter(string $text = '', ?string $lang = null);
 
        /**
         * Returns the rendered email subject as string
index 0e7bc395f2aae73e968de26fe046dcff5ab29191..8e6f1b41ac71106744ee6e5c89790694ee8f7684 100644 (file)
@@ -70,7 +70,7 @@ class NewUserMailHelperTest extends TestCase {
                $template = new EMailTemplate(
                        $this->defaults,
                        $this->urlGenerator,
-                       $this->l10n,
+                       $this->l10nFactory,
                        'test.TestTemplate',
                        []
                );
index d4687c44b069d4d61844e144843fe3fe283fea94..713f19307fc9560ee57f9906d67f7b04cae1b2cd 100644 (file)
@@ -27,6 +27,7 @@ use OC\Mail\EMailTemplate;
 use OCP\Defaults;
 use OCP\IL10N;
 use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
 use Test\TestCase;
 
 class EMailTemplateTest extends TestCase {
@@ -34,7 +35,7 @@ class EMailTemplateTest extends TestCase {
        private $defaults;
        /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
        private $urlGenerator;
-       /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
+       /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
        private $l10n;
        /** @var EMailTemplate */
        private $emailTemplate;
@@ -44,7 +45,11 @@ class EMailTemplateTest extends TestCase {
 
                $this->defaults = $this->createMock(Defaults::class);
                $this->urlGenerator = $this->createMock(IURLGenerator::class);
-               $this->l10n = $this->createMock(IL10N::class);
+               $this->l10n = $this->createMock(IFactory::class);
+
+               $this->l10n->method('get')
+                       ->with('lib', '')
+                       ->willReturn($this->createMock(IL10N::class));
 
                $this->emailTemplate = new EMailTemplate(
                        $this->defaults,
index 1913cc1176c98929f85e94a18a7b60ad52833106..b71d6646c56c09253e5b36fa4ff534ff94769d37 100644 (file)
@@ -15,6 +15,7 @@ use OCP\IConfig;
 use OCP\IL10N;
 use OCP\ILogger;
 use OCP\IURLGenerator;
+use OCP\L10N\IFactory;
 use Test\TestCase;
 
 class MailerTest extends TestCase {
@@ -44,7 +45,8 @@ class MailerTest extends TestCase {
                        $this->logger,
                        $this->defaults,
                        $this->urlGenerator,
-                       $this->l10n
+                       $this->l10n,
+                       $this->createMock(IFactory::class)
                );
        }