filament: Repeater does not work with translations
Package
filament/spatie-laravel-translatable-plugin
Package Version
v3.0.40
Laravel Version
v10.22.0
Livewire Version
v3.0.2
PHP Version
PHP 8.2.9
Problem description
I have a form for editing a model with a Repeater for a hasMany relation.
With filamentphp/spatie-laravel-translatable-plugin the translation of all translatable fields of the main model works like a charm, but the translation of the translatable fields from the related models does not work.
When I switch the language with the language switcher, the fields of the main model gets updated accordingly, but not inside of the repeater.
Also after changing a translatable text from one of the related model in the Repeater, all languages gets overwritten.
Eg editing the german translation results from {"en":"Text EN","de":"Text DE"} to {"en":"New Text DE","de":"New Text DE"}.
Expected behavior
Expected behavior would be that it is possible to translate the translatable fields inside of a Repeater form element and that it behaves like the fields of the main model itself.
Steps to reproduce
To reproduce this issue you can use the linked minimal demo project which provides a Post model having many Comments. The PostResource ist setup in a way that the Comments of a Posts are in a Repeater form field. Translating the Post itself works, but translating the comments does not.
Reproduction repository
https://github.com/pdaether/filament-translation
Relevant log output
No response
About this issue
- Original URL
- State: open
- Created 10 months ago
- Reactions: 11
- Comments: 22 (5 by maintainers)
Commits related to this issue
- Fixed repeater with translation bug #8328 — committed to dmitry-udod/filament by dmitry-udod 2 months ago
- Merge pull request #12372 from dmitry-udod/3.x Fixed repeater with translation bug #8328 — committed to filamentphp/filament by danharrin 2 months ago
I would love the fix for this, I’ve tried all of the suggestions above, but none of them worked for me. Some even yielded weird results, like for example the suggestion from @chosten was saving repeater items ON LOCALE CHANGE, and with one same value for all locales.
I’ve discovered a way to resolve this issue. You just need to add the names of the relations to the
$translatableproperty in the Post Model like this:This adjustment should solve the problem smoothly.
@tahacankurt Hi! As a quick fix you can override
updatedActiveLocalemethod of theEditRecord\Concerns\Translatabletrait. For example, for this demo repository, EditPost.php should look like this:@corept I am investigating a temporary solution with storing the activeLocale in session and forcing a reload of the page, but it is messy.
@MahdiJalilvandir 👍 Perfect, I’ve tested this and it solved the problem for me as well.
Hi @pdaether, Did you ever figure this one out?