Skip to content

Add translationMode option to MLRepeater & MLNestedForm formwidgets - #76

Draft
mjauvin wants to merge 54 commits into
mainfrom
wip-ml-repeater-fields
Draft

Add translationMode option to MLRepeater & MLNestedForm formwidgets#76
mjauvin wants to merge 54 commits into
mainfrom
wip-ml-repeater-fields

Conversation

@mjauvin

@mjauvin mjauvin commented Feb 20, 2024

Copy link
Copy Markdown
Member

This allows translating internal fields of Repeater/NestedForm FormWidgets.

See `Repeater/NestedForm formwidget internal fields translation section in README.md for more details.

Fix #21

In order to test this, you can clone this branch with the following git command:

git clone -b wip-ml-repeater-fields git@github.com:wintercms/wn-translate-plugin.git plugins/winter/translate

@mjauvin mjauvin added this to the v2.1.5 milestone Feb 20, 2024
@mjauvin mjauvin self-assigned this Feb 20, 2024
@mjauvin
mjauvin marked this pull request as draft February 20, 2024 01:55
@LukeTowers
LukeTowers self-requested a review February 20, 2024 15:53
@mjauvin mjauvin changed the title Add translateFields option to MLRepeater formwidget. Add translationMode option to MLRepeater formwidget. Feb 21, 2024
@mjauvin

mjauvin commented Mar 27, 2024

Copy link
Copy Markdown
Member Author

@kubamarkiewicz have you been testing this PR ?
Feedback welcome.

@kubamarkiewicz

Copy link
Copy Markdown

@mjauvin thanks for adding translatable property, I will test it tomorrow

@mjauvin
mjauvin marked this pull request as draft March 27, 2024 17:22
@kubamarkiewicz

Copy link
Copy Markdown

@mjauvin I have tested nestedform with the translatable property in yaml file and it is working correctly! Thanks for adding it.
I have only found a minor css bug related to "fancy-layout" styles: only inside tabs language code has white color over white background so it is not visible, but it is working. I am not sure if this should be fixed in translation plugin or in winter cms styles. I will look for a css fix later.

Screenshot 2024-03-28 at 13 46 29

@kubamarkiewicz

kubamarkiewicz commented Apr 2, 2024

Copy link
Copy Markdown

@mjauvin I have done some more tests and have found a bug. When nested form/repeater definition is not placed in fields.yaml file but instead is located in a separate file and linked to the fields.yaml file like this:

fields:
    data[contacts]:
        type: repeater
        translatable: true
        translationMode: fields
        form: $/kubamarkiewicz/my_plugin/models/record/nested_fields.yaml

then the following error appears:

image

@mjauvin

mjauvin commented Apr 2, 2024

Copy link
Copy Markdown
Member Author

@kubamarkiewicz can you try the fix I just commited ?

Thanks for your help, much appreciated!

@kubamarkiewicz

Copy link
Copy Markdown

@mjauvin now it works! Thanks for the fix.

@kubamarkiewicz

Copy link
Copy Markdown

@mjauvin here it a css fix for the bug with "fancy-layout", that I have commented earlier:

kubamarkiewicz@9fb5c5c

@mjauvin

mjauvin commented Apr 4, 2024

Copy link
Copy Markdown
Member Author

@mjauvin here it a css fix for the bug with "fancy-layout", that I have commented earlier:

kubamarkiewicz@9fb5c5c

I added your css fix to this PR.

Thanks.

@nmiyazaki-chapleau

nmiyazaki-chapleau commented May 22, 2024

Copy link
Copy Markdown

I tried this PR with the stable version of wn-pages-plugin and saving a static page doesn't work at all because it cannot properly identify the static page title. The title field's translate input name ends up being RLTranslate[en][][viewBag][title], which feels wrong? Not sure, but it refuses to save.

@nmiyazaki-chapleau

nmiyazaki-chapleau commented May 22, 2024

Copy link
Copy Markdown

Static pages plugin sets its fields without arrayNames. The title formField's name is viewBag[title] without an arrayName value. This causes the method getLocaleFieldName in traits/MLControl (when isLongFormNeeded() is true) to implode an empty arrayName, thus causing the issue mentionned above.

I'm also realising this is probably normal since this is a BC and other plugins will need to update for this.

@mjauvin

mjauvin commented May 22, 2024

Copy link
Copy Markdown
Member Author

Static pages plugin sets its fields without arrayNames. The title formField's name is viewBag[title] without an arrayName value. This causes the method getLocaleFieldName in traits/MLControl (when isLongFormNeeded() is true) to implode an empty arrayName, thus causing the issue mentionned above.

I'm also realising this is probably normal since this is a BC and other plugins will need to update for this.

Thanks for reporting this.

I'll need to investigate further, but it might be required for me to cope for the case where the arrayName is not set. Otherwise, we're going to have to make a change to the pages plugin, but it should be doable in this PR.

If you want to experiement with a fix in this PR, please do so as I don't have much time to look into this at the moment.

@nmiyazaki-chapleau

Copy link
Copy Markdown

Just did PR #83 to fix the issue I mentionned, feel free to review.

@mjauvin mjauvin modified the milestones: v2.1.7, v2.1.8 Dec 8, 2024
@mjauvin mjauvin modified the milestones: v2.1.8, 2.2.0 Dec 28, 2024
@mjauvin mjauvin removed this from the v2.3.0 milestone Jul 21, 2025
LukeTowers added a commit that referenced this pull request Aug 20, 2026
Replace the global autoTranslateWhiteList config with a per-field opt-in: a
composite widget's nested sub-field is machine-translated on copy only when its
field definition declares translatable: true; everything else is copied
verbatim.

This fixes the global whitelist's structural problems (one list bleeding across
every model/widget, and collisions between same-named fields) by declaring
translatability where it belongs — at the field. It also aligns with the
translatable: true convention from #76 / issue #21, so translatability is
expressed once and consistently.

getAutoTranslatableFields() now collects translatable field names by walking the
widget's field definitions: group mode (repeater groups / blocks) and single
form mode (repeater / nestedform), descending into nested forms and stripping
@context suffixes. The autoTranslateWhiteList config key is removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow properties of jsonable attributes of a model to be translatable

5 participants