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