Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pontoon/base/templatetags/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from django.utils.http import url_has_allowed_host_and_scheme
from django.utils.safestring import mark_safe

from pontoon.base.placeables import get_placeables
from pontoon.base.simple_preview import get_simple_preview


Expand Down Expand Up @@ -86,6 +87,24 @@ def full_static(path):
return urljoin(settings.SITE_URL, static(path))


@library.filter
def highlight_placeables(text):
if not text:
return text

placeables = get_placeables(text)
escaped = html.escape(text)

for p in placeables:
escaped_p = html.escape(p)
escaped = escaped.replace(
escaped_p,
f'<mark class="placeable" data-match="{escaped_p}">{escaped_p}</mark>',
)

return markupsafe.Markup(escaped)


@library.filter
def to_json(value):
return json.dumps(value, cls=DjangoJSONEncoder)
Expand Down
10 changes: 10 additions & 0 deletions pontoon/teams/static/css/translation_memory.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@
border-radius: 3px;
}

mark.placeable {
background: var(--dark-grey-2);
border: 1px solid var(--light-grey-1);
border-radius: 2px;
color: var(--light-grey-6);
font-style: normal;
font-weight: normal;
margin: 0 1px;
}

.empty {
border: 1px solid var(--main-border-1);
border-radius: 3px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
{% for entry in tm_entries %}
<tr data-ids="{{ entry.ids }}">
<td class="source text">
{{ linkify(entry.source|highlight_matches(search_query), entry.entity_ids) }}
{{ linkify(entry.source|highlight_placeables|highlight_matches(search_query), entry.entity_ids) }}
</td>
<td class="target text">
<div class="content-wrapper">
{{ linkify(entry.target|highlight_matches(search_query), entry.entity_ids) }}
{{ linkify(entry.source|highlight_placeables|highlight_matches(search_query), entry.entity_ids) }}
</div>
<textarea>{{ entry.target }}</textarea>
</td>
Expand Down
Loading