Upgrade to 3.5.1

This commit is contained in:
Bastian Allgeier
2021-01-19 12:20:38 +01:00
parent 8f55019e01
commit 99c36fa137
119 changed files with 2973 additions and 3707 deletions

View File

@@ -2,7 +2,6 @@
namespace Kirby\Cms;
use Kirby\Data\Data;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Locale;
use Kirby\Toolkit\Str;
@@ -46,6 +45,7 @@ trait AppTranslations
return $data;
};
// the actual locale is set using $app->setCurrentTranslation()
I18n::$locale = function (): string {
if ($this->multilang() === true) {
return $this->defaultLanguage()->code();
@@ -54,11 +54,25 @@ trait AppTranslations
}
};
I18n::$fallback = function (): string {
I18n::$fallback = function (): array {
if ($this->multilang() === true) {
return $this->defaultLanguage()->code();
// first try to fall back to the configured default language
$defaultCode = $this->defaultLanguage()->code();
$fallback = [$defaultCode];
// if the default language is specified with a country code
// (e.g. `en-us`), also try with just the language code
if (preg_match('/^([a-z]{2})-[a-z]+$/i', $defaultCode, $matches) === 1) {
$fallback[] = $matches[1];
}
// fall back to the complete English translation
// as a last resort
$fallback[] = 'en';
return $fallback;
} else {
return 'en';
return ['en'];
}
};
@@ -74,6 +88,30 @@ trait AppTranslations
}
}
/**
* Returns the language code that will be used
* for the Panel if no user is logged in or if
* no language is configured for the user
*
* @return string
*/
public function panelLanguage(): string
{
if ($this->multilang() === true) {
$defaultCode = $this->defaultLanguage()->code();
// extract the language code from a language that
// contains the country code (e.g. `en-us`)
if (preg_match('/^([a-z]{2})-[a-z]+$/i', $defaultCode, $matches) === 1) {
$defaultCode = $matches[1];
}
} else {
$defaultCode = 'en';
}
return $this->option('panel.language', $defaultCode);
}
/**
* Load and set the current language if it exists
* Otherwise fall back to the default language
@@ -132,10 +170,10 @@ trait AppTranslations
/**
* Load a specific translation by locale
*
* @param string|null $locale
* @param string|null $locale Locale name or `null` for the current locale
* @return \Kirby\Cms\Translation|null
*/
public function translation(string $locale = null)
public function translation(?string $locale = null)
{
$locale = $locale ?? I18n::locale();
$locale = basename($locale);