[damned-lies] Only display fuzzy entries in MsgiddiffView
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Only display fuzzy entries in MsgiddiffView
- Date: Sat, 31 Aug 2019 10:12:54 +0000 (UTC)
commit 05d10d7a4a9aa6070fe9a8dd5e4e0cc421685339
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Aug 31 12:12:24 2019 +0200
Only display fuzzy entries in MsgiddiffView
vertimus/views.py | 47 ++++++++++++++++++++++++++++++++++++-----------
1 file changed, 36 insertions(+), 11 deletions(-)
---
diff --git a/vertimus/views.py b/vertimus/views.py
index 956db3f2..1d43fc5a 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -301,6 +301,7 @@ class QualityCheckView(PoFileActionBase):
class MsgiddiffView(PoFileActionBase):
HEADER = '''
+<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
@@ -312,6 +313,7 @@ class MsgiddiffView(PoFileActionBase):
span.noline { color: #aaa; }
del { color: red; background-color: #fed4d4; }
ins { color: green; background-color: #c8f5c8; }
+ div.separator { margin: 1em; color: #999; font-style: italic; }
</style>
</head>
<body>
@@ -330,17 +332,43 @@ class MsgiddiffView(PoFileActionBase):
line = line[6:]
return line.rstrip('\n').strip('"')
+ def line_fmt(no, line):
+ return '<span class="noline">%d</span> ' % no + html.escape(line) + '<br>'
+
yield self.HEADER
prev_id = curr_id = None
no_wrap = False
+ stored_comments = []
+ in_fuzzy = False
with open(po_file, 'r') as fh:
for noline, line in enumerate(fh.readlines(), start=1):
- if prev_id is not None:
+ if line.startswith(('#.', '#:')):
+ stored_comments.append((noline, line))
+ continue
+
+ if line == '\n':
+ in_fuzzy = False
+ stored_comments = []
+ continue
+
+ if line.startswith('#, fuzzy'):
+ in_fuzzy = True
+ diff_printed = False
+ prev_id = []
+ curr_id = []
+ no_wrap = 'no-wrap' in line
+ yield '<div class="separator">(…)</div>\n'
+ for no, com in stored_comments:
+ yield line_fmt(no, com)
+ yield line_fmt(noline, line)
+ continue
+
+ if in_fuzzy:
if line.startswith('#|'):
prev_id.append(line)
continue
elif line.startswith('msgstr "'):
- # Compute and display
+ # Compute and display inline diff
sep = '\n' if no_wrap else ''
yield (
'<div class="diff%s">' % (' nowrap' if no_wrap else '') + diff_strings(
@@ -348,17 +376,14 @@ class MsgiddiffView(PoFileActionBase):
html.escape(sep.join(strip(l) for _, l in curr_id))
) + '</div>'
)
- for _noline, _line in curr_id:
- yield '<span class="noline">%d</span> ' % _noline + html.escape(_line) + '<br>'
- prev_id = None
- else:
+ for no, _line in curr_id:
+ yield line_fmt(no, _line)
+ diff_printed = True
+ elif not diff_printed:
curr_id.append((noline, line))
continue
- if line.startswith('#, fuzzy'):
- prev_id = []
- curr_id = []
- no_wrap = 'no-wrap' in line
- yield '<span class="noline">%d</span> ' % noline + html.escape(line) + '<br>'
+ yield line_fmt(noline, line)
+
yield self.FOOTER
def get(self, request, *args, **kwargs):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]