Add a dedicated method to get the language for another user
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
ebedbf1579
commit
b997edad10
|
@ -358,6 +358,29 @@ class Factory implements IFactory {
|
||||||
return new LanguageIterator($user, $this->config);
|
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
|
* @param string $locale
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|
|
@ -126,4 +126,13 @@ interface IFactory {
|
||||||
* @since 14.0.0
|
* @since 14.0.0
|
||||||
*/
|
*/
|
||||||
public function getLanguageIterator(IUser $user = null): ILanguageIterator;
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue