Skip to content

Commit

Permalink
fix: use template tag for redering glossary badge
Browse files Browse the repository at this point in the history
This performs better than including it.
  • Loading branch information
nijel committed Feb 20, 2025
1 parent bcd59ca commit e73069d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
5 changes: 0 additions & 5 deletions weblate/templates/snippets/component-glossary-badge.html

This file was deleted.

8 changes: 2 additions & 6 deletions weblate/templates/snippets/list-objects.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,9 @@
</td>
<th class="object-link">
{% if name_source == "component_name" or name_source == "translation" %}

{% include "snippets/component-glossary-badge.html" with object=object.component %}

{% get_glossary_badge object.component %}
{% else %}

{% include "snippets/component-glossary-badge.html" %}

{% get_glossary_badge object %}
{% endif %}

{% if object.is_ghost %}
Expand Down
3 changes: 2 additions & 1 deletion weblate/templates/snippets/project-component-settings.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load i18n %}
{% load permissions %}
{% load translations %}

{% perm 'project.edit' object as user_can_edit_project %}
<p>{% trans "Version control or files to translate are configured on individual components:" %}</p>
Expand All @@ -8,7 +9,7 @@
{% for component in object.component_set.order %}
<a class="btn btn-link" href="{% url 'settings' path=component.get_url_path %}">
{{ component.name }}
{% include "snippets/component-glossary-badge.html" with object=component %}
{% get_glossary_badge component %}
</a>
{% endfor %}
</p>
Expand Down
20 changes: 13 additions & 7 deletions weblate/trans/templatetags/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
BaseStats,
CategoryLanguage,
GhostProjectLanguageStats,
GhostStats,
ProjectLanguage,
)
from weblate.utils.templatetags.icons import icon
Expand Down Expand Up @@ -1362,6 +1363,17 @@ def urlize_ugc(value, autoescape=True):
)


@register.simple_tag
def get_glossary_badge(component: Component | GhostStats) -> StrOrPromise:
if isinstance(component, Component) and component.is_glossary:
return format_html(
'<span class="label label-{}">{}</span>',
component.glossary_color,
gettext("Glossary"),
)
return ""


def get_breadcrumbs(path_object, flags: bool = True):
if isinstance(path_object, Unit):
yield from get_breadcrumbs(path_object.translation)
Expand All @@ -1376,13 +1388,7 @@ def get_breadcrumbs(path_object, flags: bool = True):
yield from get_breadcrumbs(path_object.project)
name = path_object.name
if flags:
name = format_html(
"{}{}",
name,
render_to_string(
"snippets/component-glossary-badge.html", {"object": path_object}
),
)
name = format_html("{}{}", name, get_glossary_badge(path_object))
yield path_object.get_absolute_url(), name
elif isinstance(path_object, Category):
if path_object.category:
Expand Down

0 comments on commit e73069d

Please sign in to comment.