Repository: WeblateOrg/weblate

Issue:
Better display of changes
After request #1569:

Still in the history page, new translation strings are quite hard to check/read (changed introduced maybe 6 months ago): merge of colors (red for removed characters ...) and font style (strikes for removed characters ...).

I suggest to add an option to switch between 2 display styles for the new translations, depending on user preferences.

Proposed named for this option: "Display mode for the translated strings" (in history page and / or email notifications).
Values could be "Highlight changes" or "Raw display (no change highlighted)".
Maybe the same should apply in the mail notifications.

This option can be set globally in the user profil.

Thanks,

<bountysource-plugin>

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/47410434-better-display-of-changes?utm_campaign=plugin&utm_content=tracker%2F253393&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F253393&utm_medium=issues&utm_source=github).
</bountysource-plugin>


Discussion:
There is also https://github.com/WeblateOrg/weblate/issues/1031 to add another view of changes...
Hi, I'm back on this issue because a newcomer has made a lot of changes in french translation of WebLate yesterday and, with the current history view, it's hard to judge each change (is it an improvement or the new translation is worst?).

Here are some inputs:

- I agree with #1031 that current system to mix old string value and new string value in the same line with color and font highlights is not that easy to "read"
- I confirm that mail content is far better with 2 lines. 1st line: new value for the string, 2d line: mix of the old an new value.

Questions:
Can we add this "2 lines display" by default in the History page? Should the display be customizable at user level? If so, where this option should be "toggled" (in Profile or in the history view itself)?

Waiting for your feedback,
Hi,

Happy new year to all.

Is there anything planned to improve this display and make the new translated sentences more easy to read/check? (provide a way to get rid of the changes highlights).
  
Currently this is not scheduled for next milestone.
Hi, any update on this request or on #1031?

It would be really great if translators can easily read / check the "full final translated string" in the History view. Yet I need to open the string in a new tab to check its last value ;-().
Sorry, no update so far.
This request was not very important when strings were translated for the first time. But when translators are improving existing translations both in notification emails and in the web interface, it's very hard to check / read the "real" string which will be displayed to user in the final translated app. See for instance https://hosted.weblate.org/projects/weblate/master/fr/#history or more precisely https://hosted.weblate.org/translate/weblate/master/fr/?checksum=180be3aa20b3d107

A short suggestion to solve this issue in the Web interface: add a pop-up and display the "natural" string when pointing mouse on the current "unreadable difference string" mixing red / green and strike through text ;-).

I hope this request is now strongly motivated and my "little" proposal is clear enough to catch your attention.
Hi,

This improvement becomes more and more important because we are several translators and it's very very hard to understand changes done. See an other example: https://hosted.weblate.org/translate/weblate/master/fr/?checksum=8d36677a0ae5c9bd
Change can have be done because source string has changed or because translators have different approaches ... but the issue / question remains the same: **how to read the sentence history in "clear" text?**

Hope to have been heard at last ;-)

Resolving patch:
diff --git a/weblate/trans/simplediff.py b/weblate/trans/simplediff.py
--- a/weblate/trans/simplediff.py
+++ b/weblate/trans/simplediff.py
@@ -19,32 +19,21 @@
 #
 from __future__ import unicode_literals
 
-from difflib import SequenceMatcher
+from diff_match_patch import diff_match_patch
 
 
 def html_diff(old, new):
     """Generate HTML formatted diff of two strings."""
-    diff = SequenceMatcher(None, old, new)
+    dmp = diff_match_patch()
+    diff = dmp.diff_main(old, new)
+    dmp.diff_cleanupSemantic(diff)
+
     result = []
-    for tag, oldpos1, oldpos2, newpos1, newpos2 in diff.get_opcodes():
-        if tag == 'replace':
-            result.append(
-                '<del>{0}</del><ins>{1}</ins>'.format(
-                    old[oldpos1:oldpos2], new[newpos1:newpos2]
-                )
-            )
-        elif tag == 'delete':
-            result.append(
-                '<del>{0}</del>'.format(
-                    old[oldpos1:oldpos2]
-                )
-            )
-        elif tag == 'insert':
-            result.append(
-                '<ins>{0}</ins>'.format(
-                    new[newpos1:newpos2]
-                )
-            )
-        elif tag == 'equal':
-            result.append(new[newpos1:newpos2])
+    for op, data in diff:
+        if op == dmp.DIFF_DELETE:
+            result.append('<del>{0}</del>'.format(data))
+        elif op == dmp.DIFF_INSERT:
+            result.append('<ins>{0}</ins>'.format(data))
+        elif op == dmp.DIFF_EQUAL:
+            result.append(data)
     return ''.join(result)
diff --git a/weblate/utils/requirements.py b/weblate/utils/requirements.py
--- a/weblate/utils/requirements.py
+++ b/weblate/utils/requirements.py
@@ -287,6 +287,13 @@ def get_versions():
         '0.6.1',
     ))
 
+    result.append(get_single(
+        'diff-match-patch',
+        'https://github.com/diff-match-patch-python/diff-match-patch',
+        'diff_match_patch',
+        '20121119',
+    ))
+
     return result
 
 


Test patch: