AI Translate Module Leaves Fields Empty When No Translation is Found

Created on 23 October 2024, 4 months ago

Problem/Motivation

When using the AI Translate feature in Drupal, if the AI does not find any content to translate for certain fields, those fields are left empty in the translated version of the node.

Typically, during manual translation of a node, fields from the "source" language are pre-filled, allowing users to modify what they want. The desired behavior is to maintain this consistency when using AI translation as well. That is, if a field cannot be translated, it should retain the values from the source language instead of being left blank.

Steps to reproduce

- Create a node with fields such as media, links, and address.
- Use AI Translate to translate the node.
- Observe that fields like media, links, and address are left empty in the translated version.

Proposed resolution

If the AI translation process does not generate a translation for specific fields, the values from the source language should be copied into the corresponding fields in the translated node. This ensures that untranslated fields are not left blank.

Feature request
Status

Active

Version

1.0

Component

Other Submodules

Created by

🇧🇪Belgium arwillame Belgium 🇧🇪

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

Comments & Activities

  • Issue created by @arwillame
  • First commit to issue fork.
  • @mrdalesmith opened merge request.
  • 🇪🇸Spain interdruper

    Patch #3 does not work for me, at least for image fields. Translation leaves image fields empty.

  • 🇬🇧United Kingdom MrDaleSmith

    As far as I can tell, this isn't related to this module: it only translates text strings (which would make sense) and does not do anything to the images at all.

    The call to $entity->addTranslation($lang) in AiTranslateController returns a translation with the image attached in the English lanmguage. Saving it creates a new translation within that field that does not copy the original image over. We don't have anything in the module that affects the saving opf the entity or reacts to it, so I think it's Core's translation interfaces that are not creating the image. It's not an area I know a lot about though, so possibly someone else can see something I've missed.

  • Status changed to Needs review about 1 month ago
  • @arwillame opened merge request.
  • 🇧🇪Belgium arwillame Belgium 🇧🇪

    with Merge request !395, if no translation found for the entity reference, we just copy the reference value on the translated entity.
    This way, image and all other reference from a source language will be ported on the translation.
    This feel more natural for editors since the all page looks the same instead of just having only the texts translated.

  • 🇧🇪Belgium arwillame Belgium 🇧🇪

    We have the same issue with the entity references.

    Example, if a node has an entity reference field that references a paragraph, and that paragraph references a media, the media will not be copied to the translation.

  • 🇧🇪Belgium arwillame Belgium 🇧🇪

    I Updated my MR ( 395) to integrate the fact that an entity reference can reference an other entity and it has to be translated ortakethe value from the default language as well.

    So i created a recursive to go through all the references.
    It translate any text that has been found by the extractor and copy any reference from the main language if no translation found.

  • 🇧🇪Belgium arwillame Belgium 🇧🇪

    It seem in certain cases, the media are not copied correctly, still need a bit of work to have a good solution.
    Also not a big fan of how the undefinded languages are an exception.
    if ($referencedEntity->language()->getId() === LanguageInterface::LANGCODE_NOT_SPECIFIED) {
    This is most probably the remaining issue i got.
    I'll need a bit more time to work on this.

Production build 0.71.5 2024