F
Filament10mo ago
tuseto

Filament repeater translations messed up structure on save

When create repeater first row for the model on bg language the result in the db is: {"bg":[{"name":"first","slug":"first"}],"de":""} Adding second row for same language is okay and the result is: {"bg":[{"name":"first","slug":"first"},{"name":"second","slug":"second"}],"de":""} Then when change the language to en and add the first row in the repeater everything breaks: {"bg":{"d6073341-870a-43f3-bb83-8c49d4df16bf":{"name":"first","slug":"first"},"38b95945-88e1-462b-9e8c-469766af5baf":{"name":"second","slug":"second"}},"en":[{"name":"english_first","slug":"english_first"}]} Composer.lock filament/filament: version: v3.2.121 filament/spatie-laravel-translatable-plugin: v3.3.0 repositories: https://github.com/lara-zeus/translatable (I am using lara-zeus fork of filament-translatable, because as I remember I have problems with file upload for different languages on the original filament-translatable repo) I have a repeater:
Repeater::make('files')
->schema([
TextInput::make('name')->required(),
TextInput::make('slug')->required(),
// FileUpload::make('file'),
])
->columns(2),
Repeater::make('files')
->schema([
TextInput::make('name')->required(),
TextInput::make('slug')->required(),
// FileUpload::make('file'),
])
->columns(2),
files is in my model $translatable fields files is cast as array 'files' => 'array', All model translations works as expected but repeater not.
GitHub
GitHub - lara-zeus/translatable: A Fork of the Filament spatie/lara...
A Fork of the Filament spatie/laravel-translatable Plugin - lara-zeus/translatable
11 Replies
Lara Zeus
Lara Zeus10mo ago
I have repeater in the demo https://github.com/lara-zeus/translatable-demo/blob/213d9895c3dfbb66dde509e045e3e899687516c2/app/Filament/Resources/BookResource.php#L50
{"en":{"1898ef07-2bfc-463a-9775-6b6892966232":{"name":"sdf"},"702f07f8-762c-41b2-b7d1-72c49b521252":{"name":"sdf"}},"es":[{"name":"sdf"}]}
{"en":{"1898ef07-2bfc-463a-9775-6b6892966232":{"name":"sdf"},"702f07f8-762c-41b2-b7d1-72c49b521252":{"name":"sdf"}},"es":[{"name":"sdf"}]}
but still filament can handle them
tuseto
tusetoOP10mo ago
Yes, filament handles them. I've just noticed this when my client side throws an exception because of unprocessable data. Then I've found the change in the structure in the json column on save. I just didn't know if is this changes occuring for different languages are expected to happen. And if there is a problem or not. So as it seems it is supposed to work this way. I appriciate your quick answer! Thank you!
Lara Zeus
Lara Zeus10mo ago
I'll give it more test this weekend and see if its possible to fix it 🙂 it seems it adds the UUID keys on the first lang only can you check if its happens on create only or on edit also?! since these are diff classes.
tuseto
tusetoOP10mo ago
Tomorrow will test more in depth, because it seems that the problem is not only on the first lang, nor the default one. And maybe there is something with the sequence of the actions on different language. Hope will find a patter and will write it here 🙂 Hope this will help 🙂 It is a bit hard to explain it cleaner. 1. Hitting save button will result in no hash for current language repeater data and hash added for all of the rest langs (if they are not just empty arrays). 2. This is true for both create and edit actions (when creating you traverse languages and fill the data, hit save, same will happen, current language will be without hash, all others will have) 3. Having a repeater for a lang or not, doesn't matter, because even if you don't have a repeater for a lang it is saved as empty array by default, so hashes are added for the rest of the languages. 4. Didn't found dependency with default language for the cases above. 5. Default language matters in one case - edit without repeater only in one language By default editing on every language without repeater adds empty array as data. Saving in non default language, adds the default language automatically and assigns it empty array. (bg is default) like this: {"en":[],"bg":[]} But saving in default language without repeater adds empty string for don't know how picked language in that case 'de'. (every time when this occurs the string is for 'de' language) {"bg":[],"de":""} This is not a problem and maybe never will be. I've just noticed it. You can create a resource on default lang it will be {"bg":[]} after creating just hit save and: {"bg":[],"de":""} P.S. Some similar issue is happening to files inside the repeater. Sometimes they become: "file":{"f56d1d23-f291-4166-9002-8101b2977e40":"01JBHD5YSK0NMAEP5BXHC9ABFA.pdf"} but they should be: "file":"01JBHD8PWFENG72F7XNABSJ061.pdf"
Philipp Bürger
Philipp Bürger10mo ago
Anything updates here? Facing the same issue with a fileupload. Filament handles it fine but in the frontend its not that nice to have different data formats. I remember that this bug existed a while ago but was fixed ..
Excavator
Excavator3w ago
hey @Lara Zeus - sorry for the ping, but are you aware of any changes regarding this? I'm using your fork in the latest version, and the issue is present for me.
Lara Zeus
Lara Zeus3w ago
I didn't find any fix for this unfortunately the solution is to not use the local switcher and use a component with tabs or something other way is to fill in the first lang save then switch save again the new language I need to debug more and wish if I have more than 24h a day 😂
Excavator
Excavator2w ago
Filament
Translatable Tabs by Abdulmajeed Jamaan - Filament
Automatically generate tabs for translations.
Excavator
Excavator2w ago
I'll give it a shot! I'd debug if my day had more then 24hrs as well 😄 and they say summer is supposed to be calmer, this one was ... I don't even wanna comment
Lara Zeus
Lara Zeus2w ago
yea this would work, and I also planing to use it with my own plugins too and remove the lang switcher
Excavator
Excavator7d ago
This worked perfectly - thanks for the tip!

Did you find this page helpful?