Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/private/L10N/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ public function findLocale($lang = null) {
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
*
Expand Down
7 changes: 5 additions & 2 deletions lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ public function __construct( $renderAs, $appId = '' ) {
}
// 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)) {
Expand All @@ -159,7 +162,7 @@ public function __construct( $renderAs, $appId = '' ) {
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(),
Expand Down
10 changes: 10 additions & 0 deletions lib/public/L10N/IFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public function findLanguage($app = null);
*/
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
*
Expand Down