diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-07-04 08:56:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-04 08:56:13 +0200 |
commit | 4d8b4ef3cca51012e0e0989b6cbdbc2bea8aba21 (patch) | |
tree | 8e976e52e2687ec289ce8e9f87da65dd080d01d5 /lib | |
parent | 6d2c79598ad8d322a3a439f4790979672232200a (diff) | |
parent | db8267db26e2e81ef4a39b424c5a8ea7bc124bfd (diff) | |
download | nextcloud-server-4d8b4ef3cca51012e0e0989b6cbdbc2bea8aba21.tar.gz nextcloud-server-4d8b4ef3cca51012e0e0989b6cbdbc2bea8aba21.zip |
Merge pull request #21533 from nextcloud/techdebt/noid/dedicated-method-to-get-a-users-language
Techdebt/noid/dedicated method to get a users language
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/L10N/Factory.php | 23 | ||||
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 5 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 2 | ||||
-rw-r--r-- | lib/public/L10N/IFactory.php | 9 |
4 files changed, 34 insertions, 5 deletions
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 9d9e6ac9b26..3ab62de4b97 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -359,6 +359,29 @@ class Factory implements IFactory { } /** + * Return the language to use when sending something to a user + * + * @param IUser|null $user + * @return string + * @since 20.0.0 + */ + public function getUserLanguage(IUser $user = null): string { + $language = $this->config->getSystemValue('force_language', false); + if ($language !== false) { + return $language; + } + + if ($user instanceof IUser) { + $language = $this->config->getUserValue($user->getUID(), 'core', 'lang', null); + if ($language !== null) { + return $language; + } + } + + return $this->config->getSystemValue('default_language', 'en'); + } + + /** * @param string $locale * @return bool */ diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 202b11a6c3d..ecfe282dfbf 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -1401,10 +1401,7 @@ class DefaultShareProvider implements IShareProvider { /** @var IUser $recipient */ $email = $recipient->getEMailAddress(); if ($email) { - $language = $this->config->getSystemValue('force_language', false); - $language = \is_string($language) ? $language : $this->config->getUserValue($recipient->getUID(), 'core', 'lang', null); - $language = $language ?? $this->config->getSystemValue('default_language', 'en'); - + $language = $this->l10nFactory->getUserLanguage($recipient); if (!isset($toListByLanguage[$language])) { $toListByLanguage[$language] = []; } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 289545f0a46..24aa54ea0d6 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -805,7 +805,7 @@ class Manager implements IManager { if ($user !== null) { $emailAddress = $user->getEMailAddress(); if ($emailAddress !== null && $emailAddress !== '') { - $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); + $userLang = $this->l10nFactory->getUserLanguage($user); $l = $this->l10nFactory->get('lib', $userLang); $this->sendMailNotification( $l, diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php index b9e6e603aa8..2c6db1864df 100644 --- a/lib/public/L10N/IFactory.php +++ b/lib/public/L10N/IFactory.php @@ -126,4 +126,13 @@ interface IFactory { * @since 14.0.0 */ public function getLanguageIterator(IUser $user = null): ILanguageIterator; + + /** + * Return the language to use when sending something to a user + * + * @param IUser|null $user + * @return string + * @since 20.0.0 + */ + public function getUserLanguage(IUser $user = null): string; } |