From b997edad105d38703351b89998444ab0828f7d05 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Jun 2020 17:38:58 +0200 Subject: Add a dedicated method to get the language for another user Signed-off-by: Joas Schilling --- lib/private/L10N/Factory.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/private/L10N/Factory.php') 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 @@ -358,6 +358,29 @@ class Factory implements IFactory { return new LanguageIterator($user, $this->config); } + /** + * 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 -- cgit v1.2.3