Use user locale as default in the template

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-09-10 10:19:49 +02:00
parent e9c644412c
commit df143cb72a
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
3 changed files with 33 additions and 2 deletions

View File

@ -244,6 +244,26 @@ 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($app = 'core', $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),
\OC::$server->query(Defaults::class),
\OC::$server->getAppManager(),
\OC::$server->getSession(),

View File

@ -53,6 +53,14 @@ interface IFactory {
*/
public function findLocale($lang = null);
/**
* find the matching lang from the locale
*
* @param string $locale
* @return null|string
*/
public function findLanguageFromLocale($locale = null);
/**
* Find all available languages for an app
*