After creating a job, the source is not frozen.
A source might change or get lost during translation process.

When reviewing we should recheck the source (recapture the source if available and compare it to the submitted text for translation).
If the source changed, we should warn about the changes and provide a diff for them in the review UI.
Not sure how we want to provide this in the UI.

After accepting a translation, we can still provide a diff on the translate tab (node, entities)... to show what changed since the job has been submitted...
However this conflicts on a content level to the early outline/fixing. If the changes have already been merged on job review, they're still outlined as changes.
Thus we would need to add a checkbox "Mark all changes as merged" and store a job validity timestamp (instead of job creation).

CommentFileSizeAuthor
#29 tmgmt_1686544_diff_29-interdiff.txt3.02 KBberdir
#29 tmgmt_1686544_diff_29.patch14.68 KBberdir
#26 tmgmt_1686544_diff_26.interdiff.txt3.37 KBmiro_dietiker
#26 tmgmt_1686544_diff_26.patch14.66 KBmiro_dietiker
#25 tmgmt_1686544_diff_25.patch14.1 KBmiro_dietiker
#23 interdiff-check_for_source_change-1686544-21-23.txt2.29 KBedurenye
#23 check_for_source_change-1686544-23.patch14.07 KBedurenye
#21 interdiff-check_for_source_change-1686544-19-21.txt683 bytesedurenye
#21 check_for_source_change-1686544-21.patch14.01 KBedurenye
#19 interdiff-check_for_source_change-1686544-18-19.txt2.68 KBedurenye
#19 check_for_source_change-1686544-19.patch14.01 KBedurenye
#19 check_for_source_change-1686544-19-2.png11.46 KBedurenye
#19 check_for_source_change-1686544-19-1.png14.59 KBedurenye
#18 interdiff-check_for_source_change-1686544-15-18.txt13.42 KBedurenye
#18 check_for_source_change-1686544-18.patch13.51 KBedurenye
#18 check_for_source_change-1686544-18-4.png82.15 KBedurenye
#18 check_for_source_change-1686544-18-3.png98.58 KBedurenye
#18 check_for_source_change-1686544-18-2.png99.35 KBedurenye
#18 check_for_source_change-1686544-18-1.png98.45 KBedurenye
#15 interdiff-check_for_source_change-1686544-13-15.txt3.05 KBedurenye
#15 check_for_source_change-1686544-15.patch10.81 KBedurenye
#13 interdiff-check_for_source_change-1686544-11-13.txt3.14 KBedurenye
#13 check_for_source_change-1686544-13.patch9.67 KBedurenye
#11 interdiff-check_for_source_change-1686544-9-11.txt3.8 KBedurenye
#11 check_for_source_change-1686544-11.patch9.29 KBedurenye
#9 interdiff-check_for_source_change-1686544-6-9.txt10.52 KBedurenye
#9 check_for_source_change-1686544-9.patch9.48 KBedurenye
#9 check_for_source_change-1686544-9-2.png56.86 KBedurenye
#9 check_for_source_change-1686544-9-1.png54.7 KBedurenye
#6 check_for_source_change-1686544-6.patch10.36 KBedurenye
#6 check_for_source_change-1686544-6-2.png67.43 KBedurenye
#6 check_for_source_change-1686544-6-1.png12.54 KBedurenye

Comments

ethanethan’s picture

Could this (and 1686578) even be avoided earlier in the process? For example, if a user changes source content which is source for translation job items in progress/review, they should have the option to cancel the translation job item. (Is it even possible to cancel a job item without cancelling its parent job?)

Definitely related to #1686578: Merge with existing translation on review / accept, and #1623402: Option to cancel pending translation jobs when its source content is edited.

miro_dietiker’s picture

Issue summary: View changes
Issue tags: +job workflow
miro_dietiker’s picture

Title: Check for source change on review » Check for source change on review and show diff
Version: 7.x-1.x-dev » 8.x-1.x-dev
Related issues: +#1686578: Merge with existing translation on review / accept

Updating title and promoting to 8.x working context.

miro_dietiker’s picture

Priority: Normal » Major

Promoting as user is not aware of a potential inconsistent situation.

edurenye’s picture

Assigned: Unassigned » edurenye
edurenye’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new12.54 KB
new67.43 KB
new10.36 KB

Here is the first approach:

Also added tests.

In a followup we can improve the UI and in another integrate it with the diff module.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Controller/DataItemDiffController.php
    @@ -0,0 +1,84 @@
    +    $diff_rows = array();
    +    $build = array(
    +      '#title' => $this->t('Revisions for %title', array('%title' => $item->label())),
    +    );
    

    diff left-over?

  2. +++ b/src/Controller/DataItemDiffController.php
    @@ -0,0 +1,84 @@
    +    $diff_header = ['Current text', 'New text'];
    

    missing t()

  3. +++ b/src/Controller/DataItemDiffController.php
    @@ -0,0 +1,84 @@
    +      '#url' => Url::fromRoute('entity.tmgmt_job_item.canonical', ['tmgmt_job_item' => $item->id()]),
    

    why not $item->toUrl()?

  4. +++ b/src/Form/JobItemForm.php
    @@ -176,6 +178,13 @@ class JobItemForm extends TmgmtFormBase {
    +    $actions['has_changed_source'] = array(
    +      '#type' => 'submit',
    +      '#value' => t('Has changed'),
    +      '#access' => !$item->isAccepted(),
    +      '#validate' => ['::hasChangedSource'],
    +      '#submit' => ['::submitForm'],
    +    );
    

    i don't think we want this as a a button.

    We should just always check it when looking a review-form of a not yet accepted job item.

  5. +++ b/src/Form/JobItemForm.php
    @@ -670,4 +687,36 @@ class JobItemForm extends TmgmtFormBase {
    +    foreach ($form_state->getValues() as $field => $value) {
    +      if (is_array($value) && isset($value['translation'])) {
    +        $keys = \Drupal::service('tmgmt.data')->ensureArrayKey($field);
    +        $new_data = \Drupal::service('tmgmt.data')->flatten($item->getSourceData());
    +        $current_data = $item->getData($keys);
    +        $target_key = str_replace('|', '][', $field);
    +        if ($current_data['#text'] != $new_data[$target_key]['#text']) {
    +          $source_changed[$field] = 'The source has changed. ' . Link::fromTextAndUrl('View diff', Url::fromRoute('tmgmt.data_item_diff', [
    +            'tmgmt_job_item' => $item->id(),
    

    I don't think we need to involve the translation or values in the form structure here. Just compare the data of the job item with what the source returns.

miro_dietiker’s picture

Yeah agree, we can always check. I was just not fully sure if we should do so on every single page load and if the operation is too heavy...
Thus i defined it is only executed on button click.

If you see no issue with always checking, then yes please. It simplifies the UI and improves user awareness. One button less and less risk the check is omitted. :-)

Anyway i'm not sure, but:
When the user resolved the diff situation and accepted the data item, the warning should go away. At least no more escalate.
Unsure how we handle the situation to still access the diff -- or if we would update the source. But then we need source revisions also...
A small diff could be shown inline instead of the error. But no complex output.
Or with the proposed WYSWYG editor and the HTML tree correllation, we could add a marker and outline the change with specific WYSIWYG support.

This all could be a discussion in followups. And there are even more things to consider.

edurenye’s picture

Done.

Here the new screenshots:

On click "Show diff":

Status: Needs review » Needs work

The last submitted patch, 9: check_for_source_change-1686544-9.patch, failed testing.

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new9.29 KB
new3.8 KB

Fixed tests.

Status: Needs review » Needs work

The last submitted patch, 11: check_for_source_change-1686544-11.patch, failed testing.

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new9.67 KB
new3.14 KB

Now should be fixed, added the case when the field is removed.

I'll open a followup for when a field is added, to add also a message, in this case the user probably should abort the job if it's possible and create a new translation.

Status: Needs review » Needs work

The last submitted patch, 13: check_for_source_change-1686544-13.patch, failed testing.

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new10.81 KB
new3.05 KB

Found a new case, when you directly remove all the source. I just add the message for each element as was removed.
Not sure if is the best solution, but we already have a message that the source was removed, but I think just appears when you try to save as completed.

miro_dietiker’s picture

Status: Needs review » Needs work

I think we should display one error message when the source is gone. And skip the per-data check / output.
Also i think you should indent (left+right) the output like the other things (revision, comment) are.

And i think we would want to have the button "Resolve" added in this issue that just updates the source with the new value and makes the diff message go away.

BTW The screen above doesn't look like a +/- diff. Do you have the diff engine triggered now or just show raw source values on both sides?

mbovan’s picture

Issue summary: View changes

Referring to #2690037: Check if source url of a job item exists on JobItemForm #10 : We should cover the case when source doesn't exist at all. (e.g. it was deleted or lost)

edurenye’s picture

Done. Here some screenshots:

Source modified.

Field deleted.

Resolved the conflict.

Removed the the whole source.

edurenye’s picture

Done the following changes:

I'll create a followup for the case where we add a new field.
And open an issue in core to fix that CSS.

miro_dietiker’s picture

If i click resolve on a WSYWYG field, then revisions are dropped. That's bad. :-)

Also when editing demo nodes and save without a change, i see changes on body. It seems we are lacking p tags on demo and that's bad...

edurenye’s picture

Fixed the first thing, now I'm keeping the structure, and as I'm just comparing the translatable texts I thing is not possible that in case of a change in the structure we can not resolve a change, so should work fine.

I could not reproduce the second thing.

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/css/tmgmt.admin.css
@@ -230,3 +234,7 @@ td.views-field-tjid a {
+table.diff {

Still needs the prefix for our TMGMT scope. And plz document the workaround..
(A reference to the core bug / issue would even be better!)

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new14.07 KB
new2.29 KB

I did this and also created this followups:
#2693671: Add missing tags and text format in tmgmt_demo
#2693673: Check for added fields in the source

Is still missing the core issue for the CSS as I don't know how to see the diff.

miro_dietiker’s picture

Status: Needs review » Needs work

The UI text reads "Show diff" which is a technical term. To make users understand, we should label it "Show changes".

miro_dietiker’s picture

Status: Needs work » Needs review
StatusFileSize
new14.1 KB

Changing button label. Rerolling, conflicted.

miro_dietiker’s picture

Some missing t() and added more comments about the workflow. And renamed source change method.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/JobItemForm.php
    @@ -725,4 +811,71 @@ class JobItemForm extends TmgmtFormBase {
    +          $source_changed[$field] = 'This data item has been removed from the source.';
    +          $form_state->setValue('removed' . $field, TRUE);
    +        }
    

    using setValue() seems wrong for this, that's for form values. Should just use set/get? also don't really like the combined key, maybe use an underscore? or an array of removed keys, but that would be more complicated to work with.

  2. +++ b/src/Form/JobItemForm.php
    @@ -725,4 +811,71 @@ class JobItemForm extends TmgmtFormBase {
    +    $form_state->setValue('show_diff' . $target_key, TRUE);
    

    same here.

  3. +++ b/src/Form/JobItemForm.php
    @@ -725,4 +811,71 @@ class JobItemForm extends TmgmtFormBase {
    +    $tmgmt_data_item = str_replace('][', '|', $target_key);
    +    $key = \Drupal::service('tmgmt.data')->ensureArrayKey($tmgmt_data_item);
    +    $first_key = reset($key);
    +    $source_data = $item->getSourceData();
    +    $new_data = \Drupal::service('tmgmt.data')->flatten($source_data)[$target_key];
    

    Quite a bit of repeated code here, but we can try to improve that later, I've been thinking before about a shared trait between the two translate/review forms.

  4. +++ b/src/Form/JobItemForm.php
    @@ -725,4 +811,71 @@ class JobItemForm extends TmgmtFormBase {
    +    $form_state->setValue('show_diff' . $target_key, FALSE);
    

    and more setValue()

  5. +++ b/tmgmt.theme.inc
    @@ -265,6 +266,18 @@ function theme_tmgmt_translator_review_form($variables) {
    +      if (isset($element[$key]['source_changed']['message'])) {
    +        $source_changed = '<div class="tmgmt_source_changed"><div class="messages messages--warning"><span class="tmgmt-review-message-inline"><span>' . $element[$key]['source_changed']['message']['#value'] . '</span>' . \Drupal::service('renderer')
    +            ->render($element[$key]['source_changed']['diff_button']) . '</span></div></div>';
    +        $diff_actions = '';
    

    Is the message here safe? could be a problem if we embed it into HTML like this, we don't have twig autoescape support in here. might look into finally refactoring this into a twig template when this is in.

miro_dietiker’s picture

+          $form_state->setValue('removed' . $field, TRUE);
...
+    $form_state->setValue('show_diff' . $target_key, TRUE);

Yeah an array 'removed' or so would be much better as structure.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new14.68 KB
new3.02 KB

Improved that, added more missing t() calls.

reviewFormElement() is now 300 lines of code, with enough conditions to let every complexity code analyze tool implode :(

Also, we don't have to do that here but i think we should also have a Resolve button for deleted items, which would then remove the data item? (Probably named Remove, not Resolve).

  • Berdir committed fcbe7c5 on 8.x-1.x
    Issue #1686544 by edurenye, miro_dietiker, Berdir: Check for source...
berdir’s picture

Status: Needs review » Fixed

I think we can look at improving the data item removed scenario in a follow-up. Committed.

miro_dietiker’s picture

Awesome this is in. Thanks for hard work!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.