|
43 | 43 | use OCP\Files\Folder; |
44 | 44 | use OCP\Files\IRootFolder; |
45 | 45 | use OCP\Files\Node; |
| 46 | +use OCP\IConfig; |
46 | 47 | use OCP\IDBConnection; |
47 | 48 | use OCP\IGroupManager; |
48 | | -use OCP\IL10N; |
49 | 49 | use OCP\IURLGenerator; |
50 | 50 | use OCP\IUser; |
51 | 51 | use OCP\IUserManager; |
| 52 | +use OCP\L10N\IFactory; |
52 | 53 | use OCP\Mail\IMailer; |
53 | 54 | use OCP\Share\Exceptions\ShareNotFound; |
54 | 55 | use OCP\Share\IShare; |
@@ -82,41 +83,34 @@ class DefaultShareProvider implements IShareProvider { |
82 | 83 | /** @var Defaults */ |
83 | 84 | private $defaults; |
84 | 85 |
|
85 | | - /** @var IL10N */ |
86 | | - private $l; |
| 86 | + /** @var IFactory */ |
| 87 | + private $l10nFactory; |
87 | 88 |
|
88 | 89 | /** @var IURLGenerator */ |
89 | 90 | private $urlGenerator; |
90 | 91 |
|
91 | | - /** |
92 | | - * DefaultShareProvider constructor. |
93 | | - * |
94 | | - * @param IDBConnection $connection |
95 | | - * @param IUserManager $userManager |
96 | | - * @param IGroupManager $groupManager |
97 | | - * @param IRootFolder $rootFolder |
98 | | - * @param IMailer $mailer ; |
99 | | - * @param Defaults $defaults |
100 | | - * @param IL10N $l |
101 | | - * @param IURLGenerator $urlGenerator |
102 | | - */ |
| 92 | + /** @var IConfig */ |
| 93 | + private $config; |
| 94 | + |
103 | 95 | public function __construct( |
104 | 96 | IDBConnection $connection, |
105 | 97 | IUserManager $userManager, |
106 | 98 | IGroupManager $groupManager, |
107 | 99 | IRootFolder $rootFolder, |
108 | 100 | IMailer $mailer, |
109 | 101 | Defaults $defaults, |
110 | | - IL10N $l, |
111 | | - IURLGenerator $urlGenerator) { |
| 102 | + IFactory $l10nFactory, |
| 103 | + IURLGenerator $urlGenerator, |
| 104 | + IConfig $config) { |
112 | 105 | $this->dbConn = $connection; |
113 | 106 | $this->userManager = $userManager; |
114 | 107 | $this->groupManager = $groupManager; |
115 | 108 | $this->rootFolder = $rootFolder; |
116 | 109 | $this->mailer = $mailer; |
117 | 110 | $this->defaults = $defaults; |
118 | | - $this->l = $l; |
| 111 | + $this->l10nFactory = $l10nFactory; |
119 | 112 | $this->urlGenerator = $urlGenerator; |
| 113 | + $this->config = $config; |
120 | 114 | } |
121 | 115 |
|
122 | 116 | /** |
@@ -1401,45 +1395,58 @@ private function propagateNote(IShare $share) { |
1401 | 1395 | * @throws \OCP\Files\NotFoundException |
1402 | 1396 | */ |
1403 | 1397 | private function sendNote(array $recipients, IShare $share) { |
1404 | | - $toList = []; |
| 1398 | + $toListByLanguage = []; |
1405 | 1399 |
|
1406 | 1400 | foreach ($recipients as $recipient) { |
1407 | 1401 | /** @var IUser $recipient */ |
1408 | 1402 | $email = $recipient->getEMailAddress(); |
1409 | 1403 | if ($email) { |
1410 | | - $toList[$email] = $recipient->getDisplayName(); |
| 1404 | + $language = $this->config->getSystemValue('force_language', false); |
| 1405 | + $language = \is_string($language) ? $language : $this->config->getUserValue($recipient->getUID(), 'core', 'lang', null); |
| 1406 | + $language = $language ?? $this->config->getSystemValue('default_language', 'en'); |
| 1407 | + |
| 1408 | + if (!isset($toListByLanguage[$language])) { |
| 1409 | + $toListByLanguage[$language] = []; |
| 1410 | + } |
| 1411 | + $toListByLanguage[$language][$email] = $recipient->getDisplayName(); |
1411 | 1412 | } |
1412 | 1413 | } |
1413 | 1414 |
|
1414 | | - if (!empty($toList)) { |
| 1415 | + if (empty($toListByLanguage)) { |
| 1416 | + return; |
| 1417 | + } |
| 1418 | + |
| 1419 | + foreach ($toListByLanguage as $l10n => $toList) { |
1415 | 1420 | $filename = $share->getNode()->getName(); |
1416 | 1421 | $initiator = $share->getSharedBy(); |
1417 | 1422 | $note = $share->getNote(); |
1418 | 1423 |
|
| 1424 | + $l = $this->l10nFactory->get('lib', $l10n); |
| 1425 | + |
1419 | 1426 | $initiatorUser = $this->userManager->get($initiator); |
1420 | 1427 | $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
1421 | 1428 | $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
1422 | | - $plainHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]); |
1423 | | - $htmlHeading = $this->l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]); |
| 1429 | + $plainHeading = $l->t('%1$s shared »%2$s« with you and wants to add:', [$initiatorDisplayName, $filename]); |
| 1430 | + $htmlHeading = $l->t('%1$s shared »%2$s« with you and wants to add', [$initiatorDisplayName, $filename]); |
1424 | 1431 | $message = $this->mailer->createMessage(); |
1425 | 1432 |
|
1426 | 1433 | $emailTemplate = $this->mailer->createEMailTemplate('defaultShareProvider.sendNote'); |
1427 | 1434 |
|
1428 | | - $emailTemplate->setSubject($this->l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName])); |
| 1435 | + $emailTemplate->setSubject($l->t('»%s« added a note to a file shared with you', [$initiatorDisplayName])); |
1429 | 1436 | $emailTemplate->addHeader(); |
1430 | 1437 | $emailTemplate->addHeading($htmlHeading, $plainHeading); |
1431 | 1438 | $emailTemplate->addBodyText(htmlspecialchars($note), $note); |
1432 | 1439 |
|
1433 | 1440 | $link = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]); |
1434 | 1441 | $emailTemplate->addBodyButton( |
1435 | | - $this->l->t('Open »%s«', [$filename]), |
| 1442 | + $l->t('Open »%s«', [$filename]), |
1436 | 1443 | $link |
1437 | 1444 | ); |
1438 | 1445 |
|
1439 | 1446 |
|
1440 | 1447 | // The "From" contains the sharers name |
1441 | 1448 | $instanceName = $this->defaults->getName(); |
1442 | | - $senderName = $this->l->t( |
| 1449 | + $senderName = $l->t( |
1443 | 1450 | '%1$s via %2$s', |
1444 | 1451 | [ |
1445 | 1452 | $initiatorDisplayName, |
|
0 commit comments