diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2018-09-19 16:06:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-19 16:06:35 +0200 |
commit | b026b5deb040631cf2c22b558cba5cbda3bfc5fb (patch) | |
tree | a5d7e6b184ade0716a8b3d51361d84027a384d82 | |
parent | 12977a257dde1d56471a5b6503838d98aafd44bc (diff) | |
parent | 1e9ab0a3672dbc1255b2531f5656377cf5b23976 (diff) | |
download | nextcloud-server-b026b5deb040631cf2c22b558cba5cbda3bfc5fb.tar.gz nextcloud-server-b026b5deb040631cf2c22b558cba5cbda3bfc5fb.zip |
Merge pull request #11134 from nextcloud/locale-template-fix
Use user locale as default in the template
-rw-r--r-- | lib/private/L10N/Factory.php | 19 | ||||
-rw-r--r-- | lib/private/TemplateLayout.php | 7 | ||||
-rw-r--r-- | lib/public/L10N/IFactory.php | 10 |
3 files changed, 34 insertions, 2 deletions
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index cc2de174509..1c56949c40d 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -245,6 +245,25 @@ class Factory implements IFactory { } /** + * find the matching lang from the locale + * + * @param string $app + * @param string $locale + * @return null|string + */ + public function findLanguageFromLocale(string $app = 'core', string $locale = null) { + if ($this->languageExists($app, $locale)) { + return $locale; + } + + // Try to split e.g: fr_FR => fr + $locale = explode('_', $locale)[0]; + if ($this->languageExists($app, $locale)) { + return $locale; + } + } + + /** * Find all available languages for an app * * @param string|null $app App id or null for core diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 0bd57c4139b..316e122e2c9 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -139,9 +139,12 @@ class TemplateLayout extends \OC_Template { } // Send the language and the locale to our layouts $lang = \OC::$server->getL10NFactory()->findLanguage(); + $locale = \OC::$server->getL10NFactory()->findLocale($lang); + $localeLang = \OC::$server->getL10NFactory()->findLanguageFromLocale('lib', $locale); + $lang = str_replace('_', '-', $lang); $this->assign('language', $lang); - $this->assign('locale', \OC::$server->getL10NFactory()->findLocale($lang)); + $this->assign('locale', $locale); if(\OC::$server->getSystemConfig()->getValue('installed', false)) { if (empty(self::$versionHash)) { @@ -159,7 +162,7 @@ class TemplateLayout extends \OC_Template { if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { $jsConfigHelper = new JSConfigHelper( - \OC::$server->getL10N('lib'), + \OC::$server->getL10N('lib', $localeLang ?: $lang), \OC::$server->query(Defaults::class), \OC::$server->getAppManager(), \OC::$server->getSession(), diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php index 1bc231e4e2e..a11977f8c03 100644 --- a/lib/public/L10N/IFactory.php +++ b/lib/public/L10N/IFactory.php @@ -54,6 +54,16 @@ interface IFactory { public function findLocale($lang = null); /** + * find the matching lang from the locale + * + * @param string $app + * @param string $locale + * @return null|string + * @since 14.0.1 + */ + public function findLanguageFromLocale(string $app = 'core', string $locale = null); + + /** * Find all available languages for an app * * @param string|null $app App id or null for core |