Merge pull request #11294 from nextcloud/stable14-locale-template-fix

[stable14] Use user locale as default in the template
This commit is contained in:
blizzz 2018-09-20 10:37:00 +02:00 committed by GitHub
commit a0f2bd8d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View File

@ -244,6 +244,25 @@ class Factory implements IFactory {
return 'en_US';
}
/**
* 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
*

View File

@ -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(),

View File

@ -53,6 +53,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
*