Skip to content

Commit

Permalink
feat(info): include basic language info in translation/language views
Browse files Browse the repository at this point in the history
This makes the information about language more visible.
  • Loading branch information
nijel committed Oct 3, 2024
1 parent 4e7632a commit 4618f69
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 88 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Not yet released.
* :ref:`autofix` for French and Breton now uses a non-breaking space before colons instead of a narrow one.
* :ref:`api` now has a preview OpenAPI specification.
* :kbd:`?` now displays available :ref:`keyboard`.
* Translation and language view in the project now include basic information about the language and plurals.

**Bug fixes**

Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/language-project.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</div>

<div class="tab-pane" id="information">
{% show_info project=project stats=language_stats metrics=object|metrics %}
{% show_info project=project language=language stats=language_stats metrics=object|metrics show_full_language=False %}
</div>

<div class="tab-pane" id="history">
Expand Down
10 changes: 5 additions & 5 deletions weblate/templates/snippets/git-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% if user_can_see_git_repository %}
<tr>
<th>{% trans "Source code repository" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{% with repo_url=object.get_repo_url %}
{% if repo_url|slice:":8" == "https://" %}
<a href="{{ repo_url }}"><code class="wrap-text">{{ repo_url }}</code></a>
Expand All @@ -25,7 +25,7 @@

<tr>
<th>{% trans "Repository branch" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{{ object.get_repo_branch }}
</td>
</tr>
Expand All @@ -34,7 +34,7 @@
{% if commit %}
<tr>
<th>{% trans "Last remote commit" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{{ commit.summary }}
<code title="{{ commit.revision }}">{{ commit.shortrevision }}</code>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ commit.revision }}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
Expand All @@ -50,7 +50,7 @@
{% if commit %}
<tr>
<th>{% trans "Last commit in Weblate" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{{ commit.summary }}
<code title="{{ commit.revision }}">{{ commit.shortrevision }}</code>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ commit.revision }}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
Expand All @@ -66,7 +66,7 @@
{% if export_url %}
<tr>
<th>{% trans "Weblate repository" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
<code class="wrap-text">{{ export_url }}</code>
<button type="button" class="btn btn-link btn-xs" data-clipboard-text="{{ export_url }}" data-clipboard-message="{% trans "Repository URL copied to clipboard." %}" title="{% trans "Copy to clipboard" %}">{% icon "copy.svg" %}</button>
</td>
Expand Down
141 changes: 60 additions & 81 deletions weblate/templates/snippets/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,85 +12,18 @@
<div class="panel-heading"><h4 class="panel-title">{% trans "Overview" %}</h4></div>

<table class="table table-striped table-autowidth">
{% if language %}
<tr>
<th>{% trans "Language code" %}</th>
<td colspan="2" class="full-cell">
{% if user_can_edit_language %}
<a class="btn btn-primary btn-xs pull-right flip" href="{% url 'edit-language' pk=language.pk %}">{% trans "Edit" %}</a>
{% endif %}
{{ language.code }}
</td>
</tr>
{% with aliases=language.get_aliases_names %}
{% if aliases %}
<tr>
<th>{% trans "Aliased language codes" %}</th>
<td colspan="2">{{ aliases|join:", " }}</td>
</tr>
{% endif %}
{% endwith %}
<tr>
<th>{% trans "Text direction" %}</th>
<td colspan="2">{{ language.get_direction_display }}</td>
</tr>
{% if language.population %}
<tr>
<th>{% trans "Number of speakers" %}</th>
<td colspan="2">{{ language.population|intcomma }}</td>
</tr>
{% endif %}
{% for plural in language.plural_set.order %}
<tr class="info">
<th colspan="3">
{% if user_can_edit_language %}
<a class="btn btn-primary btn-xs pull-right flip" href="{% url 'edit-plural' pk=plural.pk %}">{% trans "Edit" %}</a>
{% endif %}
{% blocktrans with source_description=plural.get_source_display %}Plural: {{ source_description }}{% endblocktrans %}
<span class="badge">{% blocktrans count count=plural.translation_set.count %}{{ count }} translation{% plural %}{{ count }} translations{% endblocktrans %}</span>
</th>
</tr>
<tr>
<th>{% trans "Number of plurals" %}</th>
<td colspan="2">{{ plural.number }}</td>
</tr>
<tr>
<th>{% trans "Plural type" %}</th>
<td colspan="2">{{ plural.get_type_display }}</td>
</tr>
<tr>
<th rowspan="{{ plural.number }}">{% trans "Plurals" %}</th>
{% if plural.number > 1 %}
{% for item in plural.list_plurals %}
{% if item.index > 1 %}
<tr>
{% endif %}
<td>{{ item.name }}</td>
<td>{{ item.examples }}</td>
</tr>
{% endfor %}
{% else %}
<td colspan="2"></td>
</tr>
{% endif %}
<tr>
<th>{% trans "Plural formula" %}</th>
<td colspan="2" class="full-cell"><code>{{ plural.formula }}</code></td>
</tr>
{% endfor %}
{% endif %}
{% if project %}
{% if project.web %}
<tr>
<th>{% trans "Project website" %}</th>
<td class="full-cell"><a rel="ugc" href="{{ project.web }}">{{ project.web | urlformat }}</a></td>
<td colspan="2" class="full-cell"><a rel="ugc" href="{{ project.web }}">{{ project.web | urlformat }}</a></td>
</tr>
{% endif %}

{% if project.instructions %}
<tr>
<th>{% trans "Instructions for translators" %}</th>
<td class="full-cell">{{ project.instructions|markdown }}</td>
<td colspan="2" class="full-cell">{{ project.instructions|markdown }}</td>
</tr>
{% endif %}

Expand All @@ -100,7 +33,7 @@
{% if project.billings %}
<tr>
<th>{% trans "Billing" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{% for billing in project.billings %}
<a href="{{ billing.get_absolute_url }}">
{% include "billing/state-snippet.html" with object=billing %}
Expand All @@ -114,7 +47,7 @@
{% if project.all_admins %}
<tr>
<th>{% trans "Project maintainers" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{% for admin in project.all_admins %}
{{ admin.profile.get_user_display_link }}
{% endfor %}
Expand All @@ -126,7 +59,7 @@
{% regroup licenses by license as license_list %}
<tr>
<th>{% trans "Translation license" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{% for dummy, items in license_list %}
<span title="{{ items.0.get_license_display }}" class="license badge">{{ items.0.license_badge }}</span>
{% for component in items %}
Expand All @@ -140,7 +73,7 @@
{% for auto in componentlist.autocomponentlist_set.all %}
<tr>
<th>{%if forloop.first%}{% trans "Automatic component list assignment" %}{% endif %}</th>
<td><code>project ~= {{ auto.project_match }}, component ~= {{ auto.component_match }}</code></td>
<td colspan="2"><code>project ~= {{ auto.project_match }}, component ~= {{ auto.component_match }}</code></td>
</tr>
{% endfor %}
{% endif %}
Expand All @@ -149,7 +82,7 @@
{% if component.license %}
<tr>
<th>{% trans "Translation license" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{% if component.license_url %}
<a href="{{ component.license_url }}">{{ component.get_license_display }}</a>
{% else %}
Expand All @@ -162,7 +95,7 @@
{% if component.agreement %}
<tr>
<th>{% trans "Contributor agreement" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
{% if user.is_authenticated %}
<a class="btn btn-primary pull-right flip" href="{% url 'contributor-agreement' path=component.get_url_path %}">{% trans "View" %}</a>
{% endif %}
Expand All @@ -173,7 +106,7 @@

<tr>
<th>{% trans "Translation process" %}</th>
<td class="full-cell">
<td colspan="2" class="full-cell">
<ul>
{% get_workflow_flags translation component as workflow_flags %}
{% if workflow_flags.suggestion_voting and workflow_flags.suggestion_autoaccept %}
Expand Down Expand Up @@ -213,21 +146,21 @@

<tr>
<th>{% trans "File mask" %}</th>
<td><code class="wrap-text">{{ component.filemask }}</code></td>
<td colspan="2"><code class="wrap-text">{{ component.filemask }}</code></td>
</tr>

{% if component.template %}
<tr>
<th>{% trans "Monolingual base language file" %}</th>
<td><code class="wrap-text">{{ component.template }}</code></td>
<td colspan="2"><code class="wrap-text">{{ component.template }}</code></td>
</tr>
{% endif %}
{% endif %}

{% if translation %}
<tr>
<th>{% trans "Translation file" %}</th>
<td>
<td colspan="2">
{% if translation.filename %}
<a class="btn btn-primary btn-xs pull-right flip" href="{% url 'download' path=translation.get_url_path %}">{% trans "Download" %}</a>
<code class="wrap-text">{{ translation.filename }}</code>
Expand All @@ -238,12 +171,58 @@
</tr>
<tr>
<th>{% trans "Last change" %}</th>
<td>{{ stats.last_changed }}</td>
<td colspan="2">{{ stats.last_changed }}</td>
</tr>
<tr>
<th>{% trans "Last author" %}</th>
<td>{{ translation.get_last_author }}</td>
<td colspan="2">{{ translation.get_last_author }}</td>
</tr>
{% endif %}
{% if language %}
{% if not show_full_language %}
<tr>
<th>{% trans "Language" %}</th>
<td colspan="2" class="full-cell">
<a href="{% url "show_language" lang=language.code %}">{{ language }}</a>
</th>
</tr>
{% endif %}
<tr>
<th>{% trans "Language code" %}</th>
<td colspan="2" class="full-cell">
{% if user_can_edit_language %}
<a class="btn btn-primary btn-xs pull-right flip" href="{% url 'edit-language' pk=language.pk %}">{% trans "Edit" %}</a>
{% endif %}
{{ language.code }}
</td>
</tr>
{% if show_full_language %}
{% with aliases=language.get_aliases_names %}
{% if aliases %}
<tr>
<th>{% trans "Aliased language codes" %}</th>
<td colspan="2">{{ aliases|join:", " }}</td>
</tr>
{% endif %}
{% endwith %}
{% endif %}
<tr>
<th>{% trans "Text direction" %}</th>
<td colspan="2">{{ language.get_direction_display }}</td>
</tr>
{% if language.population %}
<tr>
<th>{% trans "Number of speakers" %}</th>
<td colspan="2">{{ language.population|intcomma }}</td>
</tr>
{% endif %}
{% if show_full_language %}
{% for plural in language.plural_set.order %}
{% include "snippets/plural.html" %}
{% endfor %}
{% elif translation %}
{% include "snippets/plural.html" with plural=translation.plural %}
{% endif %}
{% endif %}
</table>
</div>
Expand Down
40 changes: 40 additions & 0 deletions weblate/templates/snippets/plural.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% load i18n %}

{% if show_full_language %}
<tr class="info">
<th colspan="3">
{% if user_can_edit_language %}
<a class="btn btn-primary btn-xs pull-right flip" href="{% url 'edit-plural' pk=plural.pk %}">{% trans "Edit" %}</a>
{% endif %}
{% blocktrans with source_description=plural.get_source_display %}Plural: {{ source_description }}{% endblocktrans %}
<span class="badge">{% blocktrans count count=plural.translation_set.count %}{{ count }} translation{% plural %}{{ count }} translations{% endblocktrans %}</span>
</th>
</tr>
{% endif %}
<tr>
<th>{% trans "Number of plurals" %}</th>
<td colspan="2">{{ plural.number }}</td>
</tr>
<tr>
<th>{% trans "Plural type" %}</th>
<td colspan="2">{{ plural.get_type_display }}</td>
</tr>
<tr>
<th rowspan="{{ plural.number }}">{% trans "Plurals" %}</th>
{% if plural.number > 1 %}
{% for item in plural.list_plurals %}
{% if item.index > 1 %}
<tr>
{% endif %}
<td>{{ item.name }}</td>
<td>{{ item.examples }}</td>
</tr>
{% endfor %}
{% else %}
<td colspan="2"></td>
</tr>
{% endif %}
<tr>
<th>{% trans "Plural formula" %}</th>
<td colspan="2" class="full-cell"><code>{{ plural.formula }}</code></td>
</tr>
2 changes: 1 addition & 1 deletion weblate/templates/translation.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ <h4 class="panel-title">
</div>

<div class="tab-pane" id="information">
{% show_info project=object.component.project component=object.component translation=object stats=object.stats metrics=object|metrics %}
{% show_info project=object.component.project component=object.component translation=object language=object.language stats=object.stats metrics=object|metrics show_full_language=False %}
</div>


Expand Down
2 changes: 2 additions & 0 deletions weblate/trans/templatetags/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,7 @@ def show_info(
metrics: MetricsWrapper | None = None,
show_source: bool = False,
show_global: bool = False,
show_full_language: bool = True,
):
"""
Render project information table.
Expand All @@ -1523,4 +1524,5 @@ def show_info(
"metrics": metrics,
"show_source": show_source,
"show_global": show_global,
"show_full_language": show_full_language,
}

0 comments on commit 4618f69

Please sign in to comment.