diff --git a/src/Cms/Language.php b/src/Cms/Language.php index 21a1c5af33..f0b93496c5 100644 --- a/src/Cms/Language.php +++ b/src/Cms/Language.php @@ -62,6 +62,7 @@ public function __construct(array $props) $this->name = trim($props['name'] ?? $this->code); $this->slugs = $props['slugs'] ?? []; $this->smartypants = $props['smartypants'] ?? []; + $this->translations = (new LanguageTranslations($this))->load($props['translations'] ?? []); $this->url = $props['url'] ?? null; if ($locale = $props['locale'] ?? null) { @@ -69,8 +70,6 @@ public function __construct(array $props) } else { $this->locale = [LC_ALL => $this->code]; } - - $this->setTranslations($props['translations'] ?? []); } /** @@ -414,7 +413,7 @@ public function save(): static // inject translations from custom root // returns existing translations // if custom root is not defined as fallback - $data['translations'] = $this + $existingData['translations'] = $this ->translationsObject() ->load($existingData['translations'] ?? []); } catch (Throwable) { diff --git a/src/Cms/LanguageTranslations.php b/src/Cms/LanguageTranslations.php index e0c28c7676..1d199c59c5 100644 --- a/src/Cms/LanguageTranslations.php +++ b/src/Cms/LanguageTranslations.php @@ -117,15 +117,11 @@ public function set(string $key, string|null $value = null): static */ public function setTranslations(self|array $translations = []): static { - if (empty($translations) === false) { - if ($translations instanceof self) { - $this->data = $translations->toArray(); - } else { - $this->data = $translations; - } - } else { - $this->data = static::load(); - } + $this->data = match (true) { + empty($translations) === true => static::load(), + $translations instanceof self => $translations->toArray(), + default => $translations + }; return $this; }