Skip to content

Commit

Permalink
Apply code reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Mar 5, 2024
1 parent bbf01bf commit 296ba48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/Cms/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ 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) {
$this->locale = Locale::normalize($locale);
} else {
$this->locale = [LC_ALL => $this->code];
}

$this->setTranslations($props['translations'] ?? []);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 5 additions & 9 deletions src/Cms/LanguageTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 296ba48

Please sign in to comment.