Skip to content

Commit

Permalink
Add translation url field to package form and API
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Feb 25, 2024
1 parent 7acca7b commit 73e2a8d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/blueprints/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@ def json_schema():
"type": ["string", "null"],
"format": "uri"
},
"translation_url": {
"description": "URL to send users interested in translating your package",
"type": ["string", "null"],
"format": "uri"
}
},
})

Expand Down
2 changes: 2 additions & 0 deletions app/blueprints/packages/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class PackageForm(FlaskForm):
forums = IntegerField(lazy_gettext("Forum Topic ID"), [Optional(), NumberRange(0, 999999)])
video_url = StringField(lazy_gettext("Video URL"), [Optional(), URL()], filters=[lambda x: x or None])
donate_url = StringField(lazy_gettext("Donate URL"), [Optional(), URL()], filters=[lambda x: x or None])
translation_url = StringField(lazy_gettext("Translation URL"), [Optional(), URL()], filters=[lambda x: x or None])

submit = SubmitField(lazy_gettext("Save"))

Expand Down Expand Up @@ -323,6 +324,7 @@ def handle_create_edit(package: typing.Optional[Package], form: PackageForm, aut
"forums": form.forums.data,
"video_url": form.video_url.data,
"donate_url": form.donate_url.data,
"translation_url": form.translation_url.data,
})

if wasNew:
Expand Down
1 change: 1 addition & 0 deletions app/flatpages/help/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ curl -X DELETE https://content.minetest.net/api/delete-token/ \
* `forums`: forum topic ID.
* `video_url`: URL to a video.
* `donate_url`: URL to a donation page.
* `translation_url`: URL to send users interested in translating your package.
* `game_support`: Array of game support information objects. Not currently documented, as subject to change.
* GET `/api/packages/<author>/<name>/hypertext/`
* Converts the long description to [Minetest Markup Language](https://github.com/minetest/minetest/blob/master/doc/lua_api.md#markup-language)
Expand Down
1 change: 1 addition & 0 deletions app/flatpages/help/package_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ It should be a JSON dictionary with one or more of the following optional keys:
* `forums`: forum topic ID.
* `video_url`: URL to a video.
* `donate_url`: URL to a donation page.
* `translation_url`: URL to send users interested in translating your package.

Use `null` or `[]` to unset fields where relevant.

Expand Down
5 changes: 3 additions & 2 deletions app/logic/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def get_license(name):
"forums": int,
"video_url": str,
"donate_url": str,
"translation_url": str,
}

ALIASES = {
Expand Down Expand Up @@ -125,7 +126,7 @@ def do_edit_package(user: User, package: Package, was_new: bool, was_web: bool,

validate(data)

for field in ["short_desc", "desc", "website", "issueTracker", "repo", "video_url", "donate_url"]:
for field in ["short_desc", "desc", "website", "issueTracker", "repo", "video_url", "donate_url", "translation_url"]:
if field in data and has_blocked_domains(data[field], user.username,
f"{field} of {package.get_id()}"):
raise LogicError(403, lazy_gettext("Linking to blocked sites is not allowed"))
Expand All @@ -148,7 +149,7 @@ def do_edit_package(user: User, package: Package, was_new: bool, was_web: bool,
raise LogicError(403, "Never gonna give you up / Never gonna let you down / Never gonna run around and desert you")

for key in ["name", "title", "short_desc", "desc", "type", "dev_state", "license", "media_license",
"repo", "website", "issueTracker", "forums", "video_url", "donate_url"]:
"repo", "website", "issueTracker", "forums", "video_url", "donate_url", "translation_url"]:
if key in data:
setattr(package, key, data[key])

Expand Down
1 change: 1 addition & 0 deletions app/models/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ def as_dict(self, base_url, version=None):
"forums": self.forums,
"video_url": self.video_url,
"donate_url": self.donate_url_actual,
"translation_url": self.translation_url,

"tags": sorted([x.name for x in self.tags]),
"content_warnings": sorted([x.name for x in self.content_warnings]),
Expand Down
1 change: 1 addition & 0 deletions app/templates/packages/create_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ <h3>{{ _("Do you have a Git repository?") }}</h3>
has_view=True) }}
{{ render_field(form.video_url, class_="pkg_meta", hint=_("YouTube videos will be shown in an embed.")) }}
{{ render_field(form.donate_url, class_="pkg_meta", hint=_("If blank, the author's donation URL will be used instead.")) }}
{{ render_field(form.translation_url, class_="pkg_meta", hint=_("How can users translate your package? ie: weblate URL or a help page")) }}
</fieldset>

<div class="pkg_meta mt-5">{{ render_submit_field(form.submit) }}</div>
Expand Down
6 changes: 6 additions & 0 deletions app/templates/packages/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ <h1 class="display-3">
<span class="count">{{ _("Issue Tracker") }}</span>
</a>
{% endif %}
{% if package.translation_url %}
<a class="btn" href="{{ package.translation_url }}">
<i class="fas fa-language"></i>
<span class="count">{{ _("Translate") }}</span>
</a>
{% endif %}
<a class="btn" href="{{ package.get_url('packages.statistics') }}">
<i class="fas fa-chart-line"></i>
<span class="count">{{ _("Statistics") }}</span>
Expand Down

0 comments on commit 73e2a8d

Please sign in to comment.