diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-06-29 08:03:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-29 08:03:43 +0200 |
commit | 61842f66ee9d5b5ceb5ac925e5c213047d5a5e19 (patch) | |
tree | ccc8412bb3e0e3eb3fba7086ef3f3f1b23616685 /lib/private/Settings | |
parent | 89b6ee1a45f165346ddcc9120195714087287b47 (diff) | |
parent | c1682f4228e29cfe9203fed63e7f203dc582482b (diff) | |
download | nextcloud-server-61842f66ee9d5b5ceb5ac925e5c213047d5a5e19.tar.gz nextcloud-server-61842f66ee9d5b5ceb5ac925e5c213047d5a5e19.zip |
Merge pull request #5623 from nextcloud/locale-setting
Add user locale/region setting
Diffstat (limited to 'lib/private/Settings')
-rw-r--r-- | lib/private/Settings/Personal/PersonalInfo.php | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/private/Settings/Personal/PersonalInfo.php b/lib/private/Settings/Personal/PersonalInfo.php index 305e3fb0a4d..f4a8548e8f1 100644 --- a/lib/private/Settings/Personal/PersonalInfo.php +++ b/lib/private/Settings/Personal/PersonalInfo.php @@ -4,6 +4,7 @@ * * @author Arthur Schiwon <blizzz@arthur-schiwon.de> * @author Morris Jobke <hey@morrisjobke.de> + * @author Thomas Citharel <tcit@tcit.fr> * * @license GNU AGPL version 3 or any later version * @@ -106,6 +107,7 @@ class PersonalInfo implements ISettings { } $languageParameters = $this->getLanguages($user); + $localeParameters = $this->getLocales($user); $messageParameters = $this->getMessageParameters($userData); $parameters = [ @@ -134,7 +136,7 @@ class PersonalInfo implements ISettings { 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], 'groups' => $this->getGroups($user), 'passwordChangeSupported' => $user->canChangePassword(), - ] + $messageParameters + $languageParameters; + ] + $messageParameters + $languageParameters + $localeParameters; return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); @@ -218,6 +220,41 @@ class PersonalInfo implements ISettings { ); } + private function getLocales(IUser $user) { + $forceLanguage = $this->config->getSystemValue('force_locale', false); + if($forceLanguage !== false) { + return []; + } + + $uid = $user->getUID(); + + $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', 'en_US'); + + $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); + + $localeCodes = $this->l10nFactory->findAvailableLocales(); + + $userLocale = array_filter($localeCodes, function($value) use ($userLocaleString) { + return $userLocaleString === $value['code']; + }); + + if (!empty($userLocale)) + { + $userLocale = reset($userLocale); + } + + $localesForLanguage = array_filter($localeCodes, function($localeCode) use ($userLang) { + return 0 === strpos($localeCode['code'], $userLang); + }); + + return [ + 'activelocaleLang' => $userLocaleString, + 'activelocale' => $userLocale, + 'locales' => $localeCodes, + 'localesForLanguage' => $localesForLanguage, + ]; + } + /** * @param array $userData * @return array |