Page MenuHomePhabricator

Returning to an in-progress translation breaks references and other templates
Closed, ResolvedPublic

Description

In Content Translation it is possible to work in translations in several sessions. A user reported that continuing an in-progress translation results in problems with the references: "references will be empty and the reused ones will be wrongly numbered (since there's no content and they're all considered unique references)"

Restoring a saved translation should recover the contents without any loss. We may need to investigate which may be the cause for this not to happen with references.

Another user in T293868 reported the issue may be more general, affecting other kinds of templates. This was illustrated in the following screencast.

__

May be related: T261170: References (not using templates) disappear in content translation

Event Timeline

Pginer-WMF triaged this task as Medium priority.Mar 24 2021, 1:39 PM
Pginer-WMF created this task.
Pginer-WMF added a subscriber: santhosh.
Pginer-WMF added a subscriber: UOzurumba.

steps:
1-go to https://pt.wikipedia.org/wiki/Special:ContentTranslation?page=M-35+%28Michigan+highway%29&from=en&to=pt&targettitle=M-35+%28Michigan+highway%29
2-translate the "Tourist routes" title and paragraph
3-scroll down to references
4-translate the title and references (we get this error when translating the references list with google or yandex)

image.png (224×366 px, 5 KB)

image.png (60×592 px, 12 KB)

5-add a reference list manually using the editor
6-let the auto-save feature save the draft and go back to the dashboard
7-load the draft translation and go down to the references

  • Actual Results

this error appears and there are no references showing

image.png (84×804 px, 17 KB)

  • Expected Results

the article is loaded as it was saved before

@Pginer-WMF the issue on step 4 is new for me, should I create a new ticket for this?

@Pginer-WMF the issue on step 4 is new for me, should I create a new ticket for this?

Thanks for the details. Yes, please. a separate ticket will be helpful. thanks!

I have the same problem '⧼cx-mt-failed ⧽' when I try change from Apertium to Google Translator on a English to Spanish translation.

image.png (574×1 px, 58 KB)

Pginer-WMF raised the priority of this task from Medium to High.Oct 1 2021, 12:49 PM
Pginer-WMF renamed this task from Returning to an in-progress translation breaks references to Returning to an in-progress translation breaks references and other templates.Oct 25 2021, 10:39 AM
Pginer-WMF updated the task description. (Show Details)

Change 761228 had a related patch set uploaded (by Santhosh; author: Santhosh):

[mediawiki/extensions/ContentTranslation@master] Fix: Template edits are not restored when translation resumed

https://gerrit.wikimedia.org/r/761228

Change 761292 had a related patch set uploaded (by Santhosh; author: Santhosh):

[mediawiki/extensions/ContentTranslation@master] Render the templates in a restored translation

https://gerrit.wikimedia.org/r/761292

After the above fixes, you can see template edits are restored and rendered correctly(Ignore the page reload delay due to debug mode with VE)

The above patches address templates(block and inline) alone. There are a few other special elements like References, Maths(T222699: Edits in mw:Extension/Math content is not saved) - editing them is not triggering a section a change and hence autosave is not triggered. If the section where these elements are present is edited, along with those changes reference updates, math updates get saved. The root cause for this is in the lack of edit detectors in the VE-CX integration code. Some of these classes does not expose interfaces to listen for edit changes. The references is a complex issue because it can be a template inside sometimes. There may be ways to fix this, but I think it would be difficult without the help of VE and Cite extension developers.

The severity for those elements is minimal though because reference content usually does not change across translations. Math formula's often does not require changes across languages. Inserting new reference or math anyways trigger save and hence not a problem.

VE Team, I used onAttributeChange method override to get events for template edits https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ContentTranslation/+/761228/ But I don't see that interface in Math or other nodes. Is there a general approach that you can recommend to listen for content change events from those nodes? Edits in threse nodes should help CX to identify the section of these nodes and then triggering an autosave for the section. Is it possible to listen for edits from Surface class and then identify the source nodes and then traverse up to find parent section?

You probably shouldn't use events from the model tree to know if the document has changed. Those are mostly used just to update the view tree.

The only way to change the model is via a transaction, so you can just listen to ve.dm.Document's transact event. That will emit with a ve.dm.Transaction, which has a #getModifiedRange method. You can use that to work out what section(s) was changed: find the node in the DM tree with the start offset and traverse up to the section. You may also want to find the section for the end offset, as in theory you could have a transaction that spans multiple sections (?), then update all sections between start & end.

You probably shouldn't use events from the model tree to know if the document has changed. Those are mostly used just to update the view tree.

The only way to change the model is via a transaction, so you can just listen to ve.dm.Document's transact event. That will emit with a ve.dm.Transaction, which has a #getModifiedRange method. You can use that to work out what section(s) was changed: find the node in the DM tree with the start offset and traverse up to the section. You may also want to find the section for the end offset, as in theory you could have a transaction that spans multiple sections (?), then update all sections between start & end.

Thanks, I followed your advice and updated https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ContentTranslation/+/761228 accordingly. Would you please review?

Change 761228 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] Fix: Template edits are not restored when translation resumed

https://gerrit.wikimedia.org/r/761228

Change 761292 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] Render the templates in a restored translation

https://gerrit.wikimedia.org/r/761292

Etonkovidova subscribed.

Checked in wmf.24 - on eswiki (to check the steps in in @santhosh screen recording - works exactly as in the screen recording.

Checked cswiki wmf.24 - the article on which the issue was reported is locked for translation, en:Halcyon Days (book) is not currently available for translation; I checked some other article with the same template. All seem to be working as expected.