Browse Source
Add a dedicated method to get the language for another user
Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/21533/head
Joas Schilling
6 years ago
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with
32 additions and
0 deletions
-
lib/private/L10N/Factory.php
-
lib/public/L10N/IFactory.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 |
|
|
|
|
|
|
|
@ -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; |
|
|
|
} |