Skip to content

Commit

Permalink
Add package translations page
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Feb 25, 2024
1 parent 3749fcb commit 3f8e0e3
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/blueprints/packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def get_package_tabs(user: User, package: Package):
"title": gettext("Edit Details"),
"url": package.get_url("packages.create_edit")
},
{
"id": "translation",
"title": gettext("Translation"),
"url": package.get_url("packages.translation")
},
{
"id": "releases",
"title": gettext("Releases"),
Expand Down Expand Up @@ -70,7 +75,7 @@ def get_package_tabs(user: User, package: Package):
]

if package.type == PackageType.MOD or package.type == PackageType.TXP:
retval.insert(1, {
retval.insert(2, {
"id": "game_support",
"title": gettext("Supported Games"),
"url": package.get_url("packages.game_support")
Expand Down
8 changes: 8 additions & 0 deletions app/blueprints/packages/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ def move_to_state(package):
return redirect(package.get_url("packages.view"))


@bp.route("/packages/<author>/<name>/translation/")
@login_required
@is_package_page
def translation(package):
return render_template("packages/translation.html", package=package,
tabs=get_package_tabs(current_user, package), current_tab="translation")


@bp.route("/packages/<author>/<name>/remove/", methods=["GET", "POST"])
@login_required
@is_package_page
Expand Down
81 changes: 81 additions & 0 deletions app/templates/packages/translation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{% extends "packages/package_base.html" %}

{% block title %}
{{ _("Translation") }}
{% endblock %}

{% block content %}
{% set translations = package.translations.all() %}
{% set num = translations | length + 1 %}

<a class="btn btn-secondary float-end" href="https://api.minetest.net/translations/#translating-content-meta">
{{ _("Help") }}
</a>

<h2 class="mt-0 mb-4">{{ self.title() }}</h2>
{% if num == 1 %}
<p>
{{ _("To provide translations for your %(type)s, you need to create .tr files and upload a new release.", type=package.type.text | lower) }}
{{ _("For information on how to do this, see the modding book chapter and lua_api.md") }}
</p>
<p>
<a class="btn btn-primary me-2" href="https://rubenwardy.com/minetest_modding_book/en/quality/translations.html">
{{ _("Translation - Minetest Modding Book") }}
</a>
<a class="btn btn-primary" href="https://api.minetest.net/translations/#translating-content-meta">
{{ _("Translating content meta - lua_api.md") }}
</a>
</p>
{% else %}
<p>
{{ _("%(title)s is available in %(num)d languages.", title=package.title, num=num) }}
{{ _("ContentDB reads translations from locale files (.tr) in your package.") }}
</p>

<div class="list-group">
<div class="list-group-item">
<div class="row text-muted">
<div class="col-sm-2">
{{ _("Language") }}
</div>
<div class="col-sm">
{{ _("Title") }}
</div>
<div class="col-sm">
{{ _("Short Description") }}
</div>
</div>
</div>

<div class="list-group-item">
<div class="row">
<div class="col-sm-2">
English
</div>
<div class="col-sm">
{{ package.title }}
</div>
<div class="col-sm">
{{ package.short_desc }}
</div>
</div>
</div>

{% for translation in translations %}
<div class="list-group-item">
<div class="row">
<div class="col-sm-2">
{{ translation.language.title }}
</div>
<div class="col-sm">
{{ translation.title or "" }}
</div>
<div class="col-sm">
{{ translation.short_desc or "" }}
</div>
</div>
</div>
{% endfor %}
{% endif %}
</div>
{% endblock %}

0 comments on commit 3f8e0e3

Please sign in to comment.