Problem/Motivation
In hook_entity_translation_create we do not know what is the source translation but there might be use cases where it is needed e.g. consider that hook_entity_translation_create is implemented in order to translate the referenced entities of the parent entity and to do this the translation language from which we are translating the parent has to be known but we have no way of retrieving it.
Proposed resolution
1. TranslatableInterface::addTranslation should have a third optional parameter $source_langcode.
2. new method TranslatableInterface::translate which would translate the current entity into the desired language and call addTranslation with language of the current translation for the source parameter.
3. ContentEntityStorageInterface::createTranslation should have a fourth optional parameter $source_language, which will be set when translating an entity through TranslatableInterface::translate.
4. hook_entity_translation_create should have a second parameter : $source_langcode, which will be set when translating an entity through TranslatableInterface::translate.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#27 | interdiff_26-27.txt | 914 bytes | pooja saraah |
#27 | 2831469-27.patch | 10.88 KB | pooja saraah |
#26 | reroll_diff_11-26.txt | 11.81 KB | sahil.goyal |
#26 | 2831469-26.patch | 10.88 KB | sahil.goyal |
#11 | interdiff-6-11.txt | 668 bytes | hchonov |
Comments
Comment #2
hchonovDoes something like this have any chance?
Comment #3
hchonovOr probably TranslatableInterface::addTranslation and ContentEntityStorageInterface::createTranslation should get one more parameter - $source_langcode so that the developer could provide the source langcode when translating the entity, which could be used later in the translation hooks?
Comment #4
hchonovOr probably we need a new method having all this logic inside it : ContentEntityBase::translate($target_langcode) which would create a new translation based on the values of the current one?
Comment #5
hchonovSomething like this?
Comment #6
hchonovOups I've forgot to call addTranslation from within translate with the current langcode.
Comment #7
hchonovThis new approach would be dependent on #2831070: ContentEntityBase::toArray should return the whole entity structure by including computed properties.
Comment #9
hchonovComment #11
hchonovComment #12
hchonovComment #25
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
This seems more like a feature request to me.
This will need a test for when a src_langcode is and isn't based in to verify the behavior is fine.
Also tagging for change record.
Comment #26
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedrerolling the patch for the current version 10.1.x, making the issue to NW as per #25 test required. Attaching the reroll_diff along.
Comment #27
pooja saraah CreditAttribution: pooja saraah at Srijan | A Material+ Company for Drupal India Association commentedFixed failed commands on #26
Attached patch against Drupal 10.1.x