Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 155 forks source link

Fallback enable/disable per property? #269

Closed emilsrits closed 2 years ago

emilsrits commented 2 years ago

Is it possible to have fallback locale be used only on specific model properties?

E.g.

$locale = 'en';
$this->{"name:{$locale}"}; // does not find name in en and returns name in fallback locale, that's fine
$this->{"url:{$locale}"}; // does not find url in en, but finds it in fallback locale, do not want that in this case - give me null instead
github-actions[bot] commented 2 years ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days

marcbelletre commented 2 years ago

Just stumbled upon the same issue. It looks like there is no way to configure the fallback per property but you can return your attribute using the translate() method to prevent returning the fallback translation:

$this->translate()->url; // Returns the URL only in the current locale even if fallback_locale is set to true