wintercms / wn-translate-plugin

Translate plugin for Winter CMS
MIT License
14 stars 18 forks source link

Translations are going too deep #44

Closed AIC-BV closed 1 year ago

AIC-BV commented 2 years ago

When adding a key to the $translatable array:

$translatable = [
    'title', 'image', ...
];

I noticed that the translation is picking up all title/image/... fields What I mean with this is that when you have the following structure (simplified it):

title:
    label: Title field
repeater:
    form:
        fields:
            data:
                type: nestedForm
                    form:
                        fields:
                            title:
                                label: Title field in repeater

The translation will pick up [title] but also repeater[x][data][title]. Meaning [title] will always have the value of repeater[lastIndex][data][title]. This also occurs with my image (which I posted about in Discord), which is why when removing [image] is not working because the translation is saving repeater[lastIndex][data][image] in my [image] field

I would expect it would only pick the title/image field located in Plugin[image] and that fields inside a jsonable field are ignored.

The workaround is to create unique keys. Instead of title in repeater, use repeater_title, ... Note that repeater[x][data][title] is also getting the locale switcher thingy

image Note how RLTranslate sets image on the Blog[image] but also on Blog[blocks][0][data][image] image

AIC-BV commented 2 years ago

Found this old post, must've had the same issue months ago: https://github.com/wintercms/winter/issues/448#issuecomment-1176199547

mjauvin commented 2 years ago

Are you using the latest version of the plugin?

mjauvin commented 2 years ago

This line was added to prevent exactly that: https://github.com/wintercms/wn-translate-plugin/blob/main/classes/EventRegistry.php#L133

AIC-BV commented 2 years ago

Yes i'm on the latest version. I have that line in the Class EventRegistry.php

Composer.json has "winter/wn-translate-plugin": "~2.1.1", CMS -> Plugins -> Translate says its only 2.1.0 I ran composer update and winter:up but nothing changed

mjauvin commented 2 years ago

When you're in the create form, do you see only the top most title field with the localePicker (language selection) or do you also see this when creating the nested form title entry?

AIC-BV commented 2 years ago

It is also within the nested form title entry image

AIC-BV commented 1 year ago
title:
    label: Title field
repeater:
    form:
        fields:
            data:
                type: nestedForm
                    form:
                        fields:
                            title:
                                label: Title field in repeater

Probably cleaned code a little bit too much in my code example, fields need to be in a nestedform -> form -> tabs -> fields -> x, where 'tabs' seem to be the cause @LukeTowers

So 'tabs' need to be added in the code above for the bug to happen

AIC-BV commented 1 year ago

Can someone please look in to this? I'm willing to pay for the fix. @mjauvin @LukeTowers @bennothommo @jaxwilko https://github.com/wintercms/wn-test-plugin/pull/14