Commit 760fba74 authored by Michal Čihař's avatar Michal Čihař

Pass unit needed for proper check highlighting

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 1c73a182
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% format_translation unit.source unit.translation.subproject.project.source_language search_match=search_query num_plurals=unit.translation.language.nplurals checks=unit.checks %} {% format_translation unit.source unit.translation.subproject.project.source_language search_match=search_query num_plurals=unit.translation.language.nplurals unit=unit %}
</div> </div>
{% endif %} {% endif %}
{% endif %} {% endif %}
......
...@@ -82,14 +82,16 @@ def fmt_whitespace(value): ...@@ -82,14 +82,16 @@ def fmt_whitespace(value):
return value return value
def fmt_check_highlights(value, checks): def fmt_check_highlights(value, unit):
"""Formats check highlights""" """Formats check highlights"""
highlights = None if unit is None:
return []
# Find all checks highlight # Find all checks highlight
if checks:
highlights = [] highlights = []
for check in checks: for check in CHECKS:
highlights += check.check_obj.check_highlight(value, None) if not CHECKS[check].target:
continue
highlights += CHECKS[check].check_highlight(value, unit)
#Sort by order in string #Sort by order in string
if highlights: if highlights:
highlights.sort(key=lambda tup: tup[0]) highlights.sort(key=lambda tup: tup[0])
...@@ -107,13 +109,13 @@ def fmt_check_highlights(value, checks): ...@@ -107,13 +109,13 @@ def fmt_check_highlights(value, checks):
elif eltest[0] > elref[1]: elif eltest[0] > elref[1]:
break break
#then transform highlights to escaped html #then transform highlights to escaped html
highlights = [(h[0], escape(force_text(h[1]))) for h in highlights] highlights = [(h[0], h[1], escape(force_text(h[2]))) for h in highlights]
return highlights return highlights
@register.inclusion_tag('format-translation.html') @register.inclusion_tag('format-translation.html')
def format_translation(value, language, diff=None, search_match=None, def format_translation(value, language, diff=None, search_match=None,
simple=False, num_plurals=2, checks=None): simple=False, num_plurals=2, unit=None):
""" """
Nicely formats translation text possibly handling plurals or diff. Nicely formats translation text possibly handling plurals or diff.
""" """
...@@ -138,7 +140,7 @@ def format_translation(value, language, diff=None, search_match=None, ...@@ -138,7 +140,7 @@ def format_translation(value, language, diff=None, search_match=None,
parts = [] parts = []
for idx, value in enumerate(plurals): for idx, value in enumerate(plurals):
highlights = fmt_check_highlights(value, checks) highlights = fmt_check_highlights(value, unit)
# HTML escape # HTML escape
value = escape(force_text(value)) value = escape(force_text(value))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment