(ai_translate) One click translations for referenced entities (including reference revisions i.e. paragraphs)

Created on 26 July 2024, 5 months ago
Updated 13 September 2024, 3 months ago

Problem/Motivation

The main functionality does not support
- Paragraphs
- Layout builder.

There is a patch already for paragraphs ( https://www.drupal.org/project/chatgpt_plugin/issues/3456725 ✨ Add support for paragraphs in translations Needs work )
There is nothing (I know of) for Layouts.

Steps to reproduce

  • Create a page in aCT with Layout builder enabled.
  • Creater a nice layout with multiple text in blocks.
  • Navigate to the translate page
  • click on "Translate using GPT"
  • The Blocks will not be (but should be) translated.

Proposed resolution

We should make this so that on the translate click, that not only a copy is made with the content (in the original language) but that also that content is translated to the target language).

So very concretely what should happen in this ticket
1. Merge in the patch from this issue: https://www.drupal.org/project/chatgpt_plugin/issues/3456725 ✨ Add support for paragraphs in translations Needs work
2. Make a similar piece of code that does this for Layout builder pages.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Fixed

Version

1.0

Component

Other Submodules

Created by

πŸ‡§πŸ‡ͺBelgium wouters_f Leuven

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • 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.

  • πŸ‡§πŸ‡ͺBelgium wouters_f Leuven
  • πŸ‡§πŸ‡¬Bulgaria valthebald Sofia

    Linking ai_translate issue

  • πŸ‡§πŸ‡¬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

  • Merge request !37Resolve #3464024 "Aitranslate reference" β†’ (Merged) created by valthebald
  • Pipeline finished with Success
    5 months ago
    Total: 148s
    #241660
  • πŸ‡§πŸ‡¬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:

    1. Text extraction from entity fields is not done with plugins (of type FieldTextExctrator)
    2. Extraction of field types supported currently (hard-coded in $allowed_types variable) is moved to TextFieldExtractor, which is the only plugin so far
    3. Next step is creation of ReferenceExtractor plugin that will support entity reference and entity reference revisions
    4. 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.
    5. To mitigate possible need of batch, create a drush command that will create a translation
  • Pipeline finished with Canceled
    4 months ago
    #246869
  • Pipeline finished with Success
    4 months ago
    #246873
  • Pipeline finished with Success
    4 months ago
    #246924
  • Status changed to Needs review 4 months ago
  • πŸ‡§πŸ‡¬Bulgaria valthebald Sofia

    Here's what was done:

    1. Created new plugin type TextExtractor and accompanying plugin manager for field text extractors
    2. 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
    3. Created 2 TextExtractor plugins - text (the list of field types supported before) and entity_reference (including entity_reference_revisions)
    4. Since entity references can increase the number of texts to translate, translate controller now processes the texts in chunks
    5. 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 translatable

    Testing 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
  • πŸ‡§πŸ‡ͺBelgium wouters_f Leuven
  • Pipeline finished with Success
    4 months ago
    Total: 198s
    #248635
  • Status changed to Needs review 4 months ago
  • πŸ‡§πŸ‡¬Bulgaria valthebald Sofia

    Addressed concerns from #11:

    1. Processing every piece of content in a separate batch operation to avoid timeouts
    2. Text fields are now translated only when the field is translatable
    3. 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.

  • πŸ‡§πŸ‡ͺBelgium wouters_f Leuven
  • πŸ‡§πŸ‡¬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?)

  • Pipeline finished with Success
    4 months ago
    Total: 247s
    #255176
  • Pipeline finished with Success
    4 months ago
    #255180
  • πŸ‡«πŸ‡·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

    @yonailo what errors do you get?

  • Pipeline finished with Success
    4 months ago
    Total: 156s
    #273692
  • Pipeline finished with Success
    4 months ago
    Total: 146s
    #273703
  • πŸ‡§πŸ‡¬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

  • Pipeline finished with Success
    4 months ago
    Total: 4921s
    #274301
  • πŸ‡§πŸ‡¬Bulgaria valthebald Sofia
  • πŸ‡§πŸ‡ͺBelgium wouters_f Leuven

    Is more reviewing needed and if so who will do it?

  • Pipeline finished with Success
    3 months ago
    Total: 156s
    #279052
  • Status changed to RTBC 3 months ago
  • πŸ‡©πŸ‡ͺGermany marcus_johansson

    Code reviewed, tested and going into 1.0.x-dev!

  • Status changed to Fixed 3 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024