Skip to content

Commit

Permalink
Merge pull request #486 from thaqebon/main
Browse files Browse the repository at this point in the history
Fix casts on initialization of HasTranslation
  • Loading branch information
freekmurze authored Feb 3, 2025
2 parents 0653875 + f596f72 commit 6150f6d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/HasTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ trait HasTranslations

public function initializeHasTranslations(): void
{
$this->mergeCasts(array_merge(
$this->getCasts(),
$this->mergeCasts(
array_fill_keys($this->getTranslatableAttributes(), 'array'),
));
);
}

public static function usingLocale(string $locale): self
Expand Down Expand Up @@ -82,7 +81,9 @@ public function getTranslation(string $key, string $locale, bool $useFallbackLoc

$translations = $this->getTranslations($key);

$translation = is_null(self::getAttributeFromArray($key)) ? null : $translations[$normalizedLocale] ?? '';
$baseKey = Str::before($key, '->'); // get base key in case it is JSON nested key

$translation = is_null(self::getAttributeFromArray($baseKey)) ? null : $translations[$normalizedLocale] ?? '';

$translatableConfig = app(Translatable::class);

Expand Down

0 comments on commit 6150f6d

Please sign in to comment.