]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add a dedicated method to get the language for another user
authorJoas Schilling <coding@schilljs.com>
Mon, 22 Jun 2020 15:38:58 +0000 (17:38 +0200)
committerJoas Schilling <coding@schilljs.com>
Wed, 1 Jul 2020 08:20:07 +0000 (10:20 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/L10N/Factory.php
lib/public/L10N/IFactory.php

index 9d9e6ac9b26fe31200789fd559f4c6ba0ef901e3..3ab62de4b9710f070041c7f60f2d8899fa3a84f7 100644 (file)
@@ -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
index b9e6e603aa81a6b264fb4fe48c1303b582bb2517..2c6db1864df113ce45ca28664e2c653f5c5a32c7 100644 (file)
@@ -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;
 }