- 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
5 months ago 2:19pm 10 January 2025 - @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. - Status changed to Needs work
about 2 months ago 8:24am 17 April 2025 - 🇧🇬Bulgaria alexrayu
Hello guys, thanks for your work!
In the extractor class, the old code used to check whether the original translation field is empty, but in the current branch, it checks on the translated entity, which would have that field empty, because its not translated.
Please double check the logic against the attached interdiff which solves the problem for me by checking vs the untranslated entity.Best, Alexei.
- 🇧🇬Bulgaria alexrayu
Please ignore the prev. interdiff. Further tests revealed its faulty.
- First commit to issue fork.
- 🇮🇳India prashant.c Dharamshala
There are a lot of out of scope/not needed changes in MR https://git.drupalcode.org/project/ai/-/merge_requests/395, more seems like rebase issue etc.
MR: https://git.drupalcode.org/project/ai/-/merge_requests/248 has only one file change.
I would suggest to create a fresh new branch and cherry-pick changes from from 395 and 248.
Listing out the commits which needs to be picked:
https://git.drupalcode.org/project/ai/-/merge_requests/248/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...
https://git.drupalcode.org/project/ai/-/merge_requests/395/diffs?commit_...Above commits could have overlapping changes as well.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 3482645-copy-entity-reference to hidden.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 3482645-copy-entity-reference to active.
- @prabha1997 opened merge request.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 3482645-ai-translate-module to hidden.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 3482645-copy-reference-translated-entity to hidden.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 1.0.x to hidden.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 3482645-copy-reference-translated-entity to active.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 3482645-copy-reference-translated-entity to hidden.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 3482645-copy-entity-reference to hidden.
- 🇮🇳India prabha1997
prabha1997 → changed the visibility of the branch 3482645-copy-reference-translated-entity to active.
- 🇩🇪Germany marcus_johansson
Code wise this looks good, could someone that knows how to provoke this test the functionality of it?
- 🇫🇮Finland ronttizz Helsinki
Tested the MR as patch in one of our project.
All media types are translatable.
We have a content type with this setup:
- Hero image, can only be an image, translatable field
- Field for paragraph references (translatable field)
- A paragraph with text and media (media references to images and videos (remote and uploaded))According to my testing hero image was set to same image as the original content and media entity was not translated.
Paragraph was missing image in the translation.
So I think this patch at least somewhat working.
- 🇫🇮Finland ronttizz Helsinki
Continued testing this and I noticed that when you try to translate media entity which is translatable (with a field type file or image) and the field has the file set as not translatable and alt text/description is translatable the AI translation leaves the file field empty.
- 🇧🇬Bulgaria valthebald Sofia
My experience is the same as of @ronttizz
After some debugging, the issue is caused by the way translation is created in AiTranslateController::insertTranslation():public function insertTranslation( ContentEntityInterface $entity, string $lang_to, array &$context, ) { $translation = $entity->addTranslation($lang_to);
compared to how it is done in core's ContentTranslationController::prepareTranslation():
$target_translation = $entity->addTranslation($target->getId(), $source_translation->toArray());
i.e. in AI, translation is created with empty defaults, while in core it is prepopulated by the source entity values.
Adding the source values in AI
public function insertTranslation( ContentEntityInterface $entity, string $lang_to, array &$context, ) { $translation = $entity->addTranslation($lang_to, $entity->toArray());
solves the issue for me. Can someone confirm if this works?
- 🇮🇳India Ishani Patel
Hello,
I've tested MR with below fields:Label Field Type status
1. Image Image Translatable
2. link Link Not Translatable
3. Media image Entity reference (type:Image) Not Translatable
4. Text long Text (plain, long) Translatable
5. List List (text) Translatable
6. Taxonomy Entity reference(taxonomy) Not Translatable
As I noted like reference fields are not translatable.Thank you!
- 🇮🇳India prabha1997
It worked for me after making the change suggested by @valthebald.
I've attached screenshots for reference.
before
after
- 🇧🇬Bulgaria valthebald Sofia
@prabha1997:
I feel that the safest would be to discard the changes except the one in AiTranslateController.php
- 🇮🇳India prabha1997
As of now, translation is working correctly with only the required change applied. I’ve removed the extra check and unrelated modifications, keeping the fix minimal and focused on the actual issue.
- 🇩🇪Germany marcus_johansson
Great work everyone! This is finally getting merged!
-
marcus_johansson →
committed ab394859 on 1.1.x authored by
prabha1997 →
Resolve #3482645: 3482645-copy-reference-translated-entity
-
marcus_johansson →
committed ab394859 on 1.1.x authored by
prabha1997 →
Automatically closed - issue fixed for 2 weeks with no activity.