Update to Kirby 4.7.0

This commit is contained in:
Paul Nicoué 2025-04-21 18:57:21 +02:00
parent 02a9ab387c
commit ba25a9a198
509 changed files with 26604 additions and 14872 deletions

View file

@ -3,7 +3,6 @@
namespace Kirby\Cms;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Locale;
use Kirby\Toolkit\Str;
/**
@ -17,12 +16,10 @@ use Kirby\Toolkit\Str;
*/
trait AppTranslations
{
protected $translations;
protected Translations|null $translations = null;
/**
* Setup internationalization
*
* @return void
*/
protected function i18n(): void
{
@ -88,8 +85,6 @@ 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
{
@ -108,42 +103,12 @@ trait AppTranslations
return $this->option('panel.language', $defaultCode);
}
/**
* Load and set the current language if it exists
* Otherwise fall back to the default language
*
* @internal
* @param string|null $languageCode
* @return \Kirby\Cms\Language|null
*/
public function setCurrentLanguage(string $languageCode = null)
{
if ($this->multilang() === false) {
Locale::set($this->option('locale', 'en_US.utf-8'));
return $this->language = null;
}
$this->language = $this->language($languageCode);
$this->language ??= $this->defaultLanguage();
if ($this->language) {
Locale::set($this->language->locale());
}
// add language slug rules to Str class
Str::$language = $this->language->rules();
return $this->language;
}
/**
* Set the current translation
*
* @internal
* @param string|null $translationCode
* @return void
*/
public function setCurrentTranslation(string $translationCode = null): void
public function setCurrentTranslation(string|null $translationCode = null): void
{
I18n::$locale = $translationCode ?? 'en';
}
@ -152,11 +117,10 @@ trait AppTranslations
* Load a specific translation by locale
*
* @param string|null $locale Locale name or `null` for the current locale
* @return \Kirby\Cms\Translation
*/
public function translation(string|null $locale = null)
public function translation(string|null $locale = null): Translation
{
$locale = $locale ?? I18n::locale();
$locale ??= I18n::locale();
$locale = basename($locale);
// prefer loading them from the translations collection
@ -180,10 +144,8 @@ trait AppTranslations
/**
* Returns all available translations
*
* @return \Kirby\Cms\Translations
*/
public function translations()
public function translations(): Translations
{
if ($this->translations instanceof Translations) {
return $this->translations;
@ -207,8 +169,6 @@ trait AppTranslations
}
}
$this->translations = Translations::load($this->root('i18n:translations'), $translations);
return $this->translations;
return $this->translations = Translations::load($this->root('i18n:translations'), $translations);
}
}