CRUD
CRUD copied to clipboard
Allow manual translating field attributes
WHY
BEFORE - What was wrong? What was happening before this PR?
This is a follow-up of #3932 , that PR made it work in simpler scenarios, but would fail if your translatable attribute value was a simple array and not the expected [en => smt, fr => smt_fr]
I pushed the main PR so @kolaente and @promatik show as contributors here too.
AFTER - What is happening after this PR?
This PR checks if the array keys correspond to available locales, if they do it sets the translations, if not just follow the regular saving process.
Is it a breaking change?
I don't think so, no. There was a bug previously that we are fixing here.
How can we test the before & after?
Try manually assigning translations to a model when creating it: Model::create(['translatable_field' => ['en' => 'value en', 'fr' => 'value fr']]).
If this gets merged #3932 should be closed!
@tabacitu I merged the changes regarding the comments in doc blocks. Thanks 👍 Also commented about the method signature: https://github.com/Laravel-Backpack/CRUD/pull/4271#discussion_r841569036 Let me know if I didn't explain myself well 🙃
Cheers
@tabacitu kindly review the changes 👍 I've refactored method signatures and cleaned up the functions.
Hello @pxpm I tested the changes on a model with translatable and non-translatable attributes. Everything seems to work fine. Cheers
Hi @pxpm did this need merge with master? because i get an error.

Cheers.
I just merged master here. Next time feel free to do it yourself, if there are no code changes/conflicts you can merge master on my PR's, I am ok with it.
Cheers
Hello @pxpm i do merge with main again because in my end was needed.
I was checking on this branch, everything look to working normally, but there still something strange, let me explain.
I choose Products, and i add this: \App\Models\Product::create(['name' => ['en' => 'value en', 'fr' => 'value fr']]);
In database was created: {"en": "value en", "fr": "value fr"}

As you see everything look great on this example, but now i tried to add translation from a language who is nos enable:
\App\Models\Product::create(['name' => ['en' => 'value en', 'fr' => 'value fr', 'de' => 'value de']]);
In database was created: {"en": {"de": "value de", "en": "value en", "fr": "value fr"}}
And i get wrong results

Idk if this need to be fixed by this branch or is something who developer need to prevent.
Please let me know, thanks.
Cheers.