Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] relationship with subfields (and probably repeatable) incorrect reflection of the translatable fields #4357

Closed
guleswine opened this issue May 3, 2022 · 11 comments
Assignees

Comments

@guleswine
Copy link
Contributor

guleswine commented May 3, 2022

Bug report

What I did

i make relationship

CRUD::addField([   // relationship
            'label'=>'Answers',
            'type' => "relationship",
            'name' => 'responses',
            'subfields'   => [
                [
                    'label'=>'Question',
                    'name' => 'text',
                    'type' => 'textarea',
                    'wrapper' => [
                        'class' => 'form-group col-md-4',
                    ],
                ],
                [
                    'label'=>'Image',
                    'name' => 'img',
                    'type'=>'text',
                    'wrapper' => [
                        'class' => 'form-group col-md-4',
                    ],

                ],
                [   
                    'name' => 'buttons',
                    'label' => 'Buttons',
                    'type'=>'text',
                    'wrapper' => [
                        'class' => 'form-group col-md-4',
                    ],
                ],
            ],
            'tab'=>'Answers'
        ]);

this fields is translatable
public $translatable = ['text','img','buttons'];

What I expected to happen

reflection of blank lines when there is no data in my locale or locale has 'NULL' data

What happened

translbug

What I've already tried to fix it

vendor/backpack/pro/resources/views/fields/relationship.blade.php

I found that if there is no value for my locale, the entire value from the table field in json format gets here.

and I have no idea how to fix it except dirty check in view

Is it a bug in the latest version of Backpack?

yes

Backpack, Laravel, PHP, DB version

last versions

@guleswine guleswine changed the title [Bug] relationshinp with subfields (and probably repeatable) incorrect reflection of the translatable fields [Bug] relationship with subfields (and probably repeatable) incorrect reflection of the translatable fields May 3, 2022
@pxpm pxpm self-assigned this May 3, 2022
@pxpm pxpm added this to Triage in 📥 Inbox (in need of a deadline) via automation May 3, 2022
@pxpm
Copy link
Contributor

pxpm commented May 4, 2022

Hello @guleswine

Thanks again for one more issue report. I think I got this fixed in #4267

If you have time do you want to give it a try and let us know ? It could help alot in the review process and finding something that slipped me.

Cheers

@guleswine
Copy link
Contributor Author

guleswine commented May 4, 2022

@pxpm hi, i checked your great idea (which will be very helpful when translating models).

But it doesn't always work well and correctly.

  1. I created a new related entity in the Ru locale, which I use as a fallback
  2. The interface prompts me to switch to default values (although I already have fallback locale enabled)
  3. when switching the language to the En locale, it was already filled with the translation from the Ru locale, although I did not press the button.
  4. and again, in the text fields of the related entity, the json code is reflected, (the main problem of the bug in this topic)

tans2

config/translatable.php

return [

    /*
     * If a translation has not been set for a given locale, use this locale instead.
     */
    'fallback_locale' => 'ru',
];

P.S.
and it seems to me that a check should be added for the fact that fallback_locale => null (to not output the default reflection clause)

@pxpm pxpm added the Possible Bug A bug that was reported but not confirmed yet. label May 5, 2022
@pxpm
Copy link
Contributor

pxpm commented May 5, 2022

Hello @guleswine so that we are on the same page here:

  • You have the MultipleEventsController that uses the MultipleEvents model.
  • MultipleEvents model is translatable.
  • MultipleEvents model have a relation (I guess HasMany) with Responses model.
  • Responses model have 3 fields that are also translatable and you added all of them to the $translatable property.

So, I found an issue, but not the one you described.

  • I found out, that the models that we get from the relation didn't had the locale setup, so they always showed the "default" locale, even if they store the correct locale on database.
  • If you select any locale that does not have translations, it will show the default locale translations.

I've already come up with a solution for the first problem I described. #4359

I haven't found a solution for the second, nor I could reproduce your issue.

https://recordit.co/KJSMUzu07w

This video is made after in the branch with the mentioned pull request, without it, it would save the FR and IT values, but it would always display the EN version.

@guleswine
Copy link
Contributor Author

guleswine commented May 5, 2022

@pxpm

in your example, you have filled in both fields, but it may be worth filling out only one, and at the same time check what will be reflected with the setting fallback_locale => null

@guleswine

This comment was marked as off-topic.

@pxpm
Copy link
Contributor

pxpm commented May 5, 2022

You've been very helpful finding this corner cases, for that I thank you very much 🙏

Will have a look too on this last one you described! Cheers

@adriallongarriu
Copy link
Contributor

Hello @pxpm, i encounter this bug in the last versions. backpack/crud: 6.7.14 and backpack/pro: 2.2.0
I'll try to explain how I have it configured in case it can help.

I have model Page and a relaction hasMany to Translation.
Translation property text is translatable

protected $fillable = [
        'page_id',
        'key',
        'text'
];
protected $translatable = ['text'];

Field translations

        $this->crud->field([
            'name'          => 'translations',
            'type'          => "relationship",
            'subfields'   => [
                [
                    'name' => 'key',
                    'type' => 'text',
                    'wrapper' => [
                        'class' => 'form-group col-md-3',
                    ],
                    'attributes' => $attributes,
                ],
                [
                    'name' => 'text',
                    'type' => 'textarea',
                    'wrapper' => [
                        'class' => 'form-group col-md-9',
                    ],
                ]
            ],
            'tab' => 'Translations'
        ]);

image
I have 2 locales ES and CA. ES is the fallback_locale.
The problem is releted to the fallback locale being empty.
In my user case the translation has text in all locales but the client want to remove the text from the translation, leave it blank. After save the next time he enter to edit the page the value shows the json.

I try to debug but didn't succeed. When the value is in the array items in the repeatable.blade alerady is a json insted of a "".

@pxpm
Copy link
Contributor

pxpm commented May 27, 2024

Hey @adriallongarriu

Can you check if #4267 fixes your issue ?

You can request that branch by adding in your composer.json

"backpack/crud": "dev-translatable-with-fallbacks as 6.7"

It was revived a few weeks ago and should be merged anytime soon.

Cheers

@adriallongarriu
Copy link
Contributor

@pxpm tested with dev-translatable-with-fallbacks and it works.

@pxpm
Copy link
Contributor

pxpm commented May 30, 2024

Thanks for confirming @adriallongarriu 🙏 That's excellent news! 🥳

We should merge that PR sooner than later, we are just waiting for a colleague too give the thumbs up.
This messes with some important files and we try to make sure we don't break nothing 🙏

@pxpm
Copy link
Contributor

pxpm commented Jun 26, 2024

This should be fixed in 6.7.17 merged #4267

Let us know if that's not the case 🙏

Cheers

@pxpm pxpm closed this as completed Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants