- Issue created by @wouters_f
- πΊπΈUnited States kevinquillen
Initial thoughts - the plugin should not care about the target entity type (Paragraph item, Block, or otherwise), so long as the entity is an implementation of ContentEntityBase. In the case of Layout Builder, there are specific block types that come with it (FieldBlock, InlineBlock, ExtraFieldBlock) and a plugin should know whether or not it can operate on it. I assume that minimum threshold is if the entity has at least one text/string field and is user provided.
In the case of Layout Builder, this could easily be added as a Contextual Link:
I don't know if Paragraphs have contextual editing. I assume someone has added that maybe.
This link could lead to either a:
- Modal action window, or
- New screen with a Drupal form that ultimately redirects back to the node being edited (with the same form as the modal)
The form may ask which provider, other parameters, which language... etc.
- π§π¬Bulgaria valthebald Sofia
Shouldn't translation of paragraphs/blocks be the part of translating the host entity? I would add entity reference (and entity reference revision as a subclass of it) to the list of supported field types when translating the entity
- π©πͺGermany marcus_johansson
We should add Batch API if we do full parent entity translations. Or probably add it anyway :) Just so you don't time out.
Regarding translating all the children, there probably has to be some kind of check on each if they are translated or even if there should be a translation. Taxonomies for instance are entity references, and I could see use cases where you want to translate them separately/manually/not at all. This is probably true for some other entity references as well, like author.
- π§π¬Bulgaria valthebald Sofia
I will try to provide some PoC (including batches) tonight
- π§π¬Bulgaria valthebald Sofia
This https://git.drupalcode.org/project/ai/-/merge_requests/37/diffs is not ready for the prime time yet, but done some preparation:
- Text extraction from entity fields is not done with plugins (of type FieldTextExctrator)
- Extraction of field types supported currently (hard-coded in $allowed_types variable) is moved to TextFieldExtractor, which is the only plugin so far
- Next step is creation of ReferenceExtractor plugin that will support entity reference and entity reference revisions
- After that, add the batch creation when the number of extracted texts to translate exceeds certain level. Not sure if this should be done in the same or separate issue.
- To mitigate possible need of batch, create a drush command that will create a translation
- Status changed to Needs review
4 months ago 2:55pm 7 August 2024 - π§π¬Bulgaria valthebald Sofia
Here's what was done:
- Created new plugin type TextExtractor and accompanying plugin manager for field text extractors
- TextExtractorInterface has 2 methods: extract() that returns an array of translatable metadata (value + optional format, delta etc.) from entity field, and setValue() that does the opposite and sets translated value back into the entity
- Created 2 TextExtractor plugins - text (the list of field types supported before) and entity_reference (including entity_reference_revisions)
- Since entity references can increase the number of texts to translate, translate controller now processes the texts in chunks
- Created drush command ai:translate that does exactly the same as translate controller, but in one chunk. I know it's possible to process batches in drush as well, but not sure if that was needed
- π§πͺBelgium wouters_f Leuven
Tested this (feedback was also passed to @valthebald via slack)
Remarks (to people configuring this)
- make sure the fields in your paragraphs are transatable, otherwise this will translate the original paragraph.
- the paragraph field itself should not be translatableTesting feedback
- batch size 1 works best for me (higher sizes time out).
- IT WORKS and its super awesome!
- Valtebald said it should not look at non-translatable field (which it does now)Scope wise: we will not take into account async translations. this should be a separate issue.
Thanks for the nice work! I love it! - π§πͺBelgium wouters_f Leuven
tested the functionality (prompt) in
- mistral
- openai
So far results are pretty good. - Status changed to Needs work
4 months ago 7:22am 9 August 2024 - Status changed to Needs review
4 months ago 7:43am 9 August 2024 - π§π¬Bulgaria valthebald Sofia
Addressed concerns from #11:
- Processing every piece of content in a separate batch operation to avoid timeouts
- Text fields are now translated only when the field is translatable
- The (officially unsupported) case of translatable paragraphs reference is not handled and raises errors.
- π§πͺBelgium wouters_f Leuven
I'm going to make a separate issue for layout builder since this seems to be finished for Paragraphs and batch.
- π§π¬Bulgaria valthebald Sofia
β¨ (ai_translate) One click translations for Layout builder Active can't be resolved before this one, both issues can be either fixed together, or this one is committed earlier (possible?)
- π«π·France yonailo Paris
Hello,
I am trying to test this patch using an Umami installation of Drupal 10.3, but I've got errors when attempting to translate an article page ? Does anybody else has tried to test this with Umami ? Previous comments seem to suggest that the patch works so I don't quite understand.
Thank you in advance.
- π§π¬Bulgaria valthebald Sofia
Finally had some time to work on this.
@Marcus_Johansson:
1. I have added a third party subform to Field UI's FieldConfigEditForm:
2. Defaults lead to AI translate settings form@yonailo: I noticed (and fixed) some PHP messages coming from changes in the upstream, hopefully this fixes your case.
If not, please provide more details - π§πͺBelgium wouters_f Leuven
Is more reviewing needed and if so who will do it?
- Status changed to RTBC
3 months ago 7:23am 12 September 2024 - π©πͺGermany marcus_johansson
Code reviewed, tested and going into 1.0.x-dev!
- Status changed to Fixed
3 months ago 7:24am 12 September 2024 -
marcus_johansson β
committed 28135ef2 on 1.0.x authored by
valthebald β
Resolve #3464024 "Aitranslate reference"
-
marcus_johansson β
committed 28135ef2 on 1.0.x authored by
valthebald β
-
marcus_johansson β
committed 28135ef2 on functional-testing authored by
valthebald β
Resolve #3464024 "Aitranslate reference"
-
marcus_johansson β
committed 28135ef2 on functional-testing authored by
valthebald β
Automatically closed - issue fixed for 2 weeks with no activity.