Skip to content

Commit

Permalink
Revert return value change when column value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
vencelkatai authored and freekmurze committed Dec 16, 2024
1 parent d679f82 commit 5f07127
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/HasTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public function translate(string $key, string $locale = '', bool $useFallbackLoc

public function getTranslation(string $key, string $locale, bool $useFallbackLocale = true): mixed
{
// if column value is `null` then we have nothing to do, return `null`
if (is_null(parent::getAttributeFromArray($key))) {
return null;
}

$normalizedLocale = $this->normalizeLocale($key, $locale, $useFallbackLocale);

$isKeyMissingFromLocale = ($locale !== $normalizedLocale);
Expand Down
4 changes: 2 additions & 2 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ public function setAttributesExternally(array $attributes)
[['en' => 'english', 'nl' => 'dutch'], ['en', 'nl'], ['english', 'dutch']],
]);

it('should return null when the underlying attribute in database is null', function () {
it('should return empty string when the underlying attribute in database is null', function () {
// we need to remove the name attribute from the translatable array
// and add it back to make sure the name
// attribute is holding `null` raw value
Expand All @@ -864,7 +864,7 @@ public function setAttributesExternally(array $attributes)

$translation = $this->testModel->getTranslation('name', 'en');

expect($translation)->toBeNull();
expect($translation)->toBe('');
});

it('should return locales with empty string translations when allowEmptyStringForTranslation is true', function () {
Expand Down

0 comments on commit 5f07127

Please sign in to comment.