Allow translating text in blueprints

This commit is contained in:
rubenwardy 2022-01-07 22:11:12 +00:00
parent bd59fa8ef3
commit c8b0f9e6ce
4 changed files with 17 additions and 16 deletions

@ -15,6 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import Blueprint from flask import Blueprint
from flask_babel import gettext
from app.models import User, Package, Permission from app.models import User, Package, Permission
@ -28,37 +29,37 @@ def get_package_tabs(user: User, package: Package):
return [ return [
{ {
"id": "edit", "id": "edit",
"title": "Edit Details", "title": gettext("Edit Details"),
"url": package.getURL("packages.create_edit") "url": package.getURL("packages.create_edit")
}, },
{ {
"id": "releases", "id": "releases",
"title": "Releases", "title": gettext("Releases"),
"url": package.getURL("packages.list_releases") "url": package.getURL("packages.list_releases")
}, },
{ {
"id": "screenshots", "id": "screenshots",
"title": "Screenshots", "title": gettext("Screenshots"),
"url": package.getURL("packages.screenshots") "url": package.getURL("packages.screenshots")
}, },
{ {
"id": "maintainers", "id": "maintainers",
"title": "Maintainers", "title": gettext("Maintainers"),
"url": package.getURL("packages.edit_maintainers") "url": package.getURL("packages.edit_maintainers")
}, },
{ {
"id": "audit", "id": "audit",
"title": "Audit Log", "title": gettext("Audit Log"),
"url": package.getURL("packages.audit") "url": package.getURL("packages.audit")
}, },
{ {
"id": "share", "id": "share",
"title": "Share and Badges", "title": gettext("Share and Badges"),
"url": package.getURL("packages.share") "url": package.getURL("packages.share")
}, },
{ {
"id": "remove", "id": "remove",
"title": "Remove", "title": gettext("Remove"),
"url": package.getURL("packages.remove") "url": package.getURL("packages.remove")
} }
] ]

@ -50,7 +50,7 @@ def get_mt_releases(is_max):
class CreatePackageReleaseForm(FlaskForm): class CreatePackageReleaseForm(FlaskForm):
title = StringField(lazy_gettext("Title"), [InputRequired(), Length(1, 30)]) title = StringField(lazy_gettext("Title"), [InputRequired(), Length(1, 30)])
uploadOpt = RadioField(lazy_gettext("Method"), choices=[("upload", "File Upload")], default="upload") uploadOpt = RadioField(lazy_gettext("Method"), choices=[("upload", lazy_gettext("File Upload"))], default="upload")
vcsLabel = StringField(lazy_gettext("Git reference (ie: commit hash, branch, or tag)"), default=None) vcsLabel = StringField(lazy_gettext("Git reference (ie: commit hash, branch, or tag)"), default=None)
fileUpload = FileField(lazy_gettext("File Upload")) fileUpload = FileField(lazy_gettext("File Upload"))
min_rel = QuerySelectField(lazy_gettext("Minimum Minetest Version"), [InputRequired()], min_rel = QuerySelectField(lazy_gettext("Minimum Minetest Version"), [InputRequired()],
@ -81,7 +81,7 @@ def create_release(package):
# Initial form class from post data and default data # Initial form class from post data and default data
form = CreatePackageReleaseForm() form = CreatePackageReleaseForm()
if package.repo is not None: if package.repo is not None:
form["uploadOpt"].choices = [("vcs", "Import from Git"), ("upload", "Upload .zip file")] form["uploadOpt"].choices = [("vcs", gettext("Import from Git")), ("upload", gettext("Upload .zip file"))]
if request.method == "GET": if request.method == "GET":
form["uploadOpt"].data = "vcs" form["uploadOpt"].data = "vcs"
form.vcsLabel.data = request.args.get("ref") form.vcsLabel.data = request.args.get("ref")

@ -137,7 +137,7 @@ def handle_register(form):
user_by_email = User.query.filter_by(email=form.email.data).first() user_by_email = User.query.filter_by(email=form.email.data).first()
if user_by_email: if user_by_email:
send_anon_email.delay(form.email.data, "Email already in use", send_anon_email.delay(form.email.data, gettext("Email already in use"),
gettext("We were unable to create the account as the email is already in use by %(display_name)s. Try a different email address.", gettext("We were unable to create the account as the email is already in use by %(display_name)s. Try a different email address.",
display_name=user_by_email.display_name)) display_name=user_by_email.display_name))
return redirect(url_for("flatpage", path="email_sent")) return redirect(url_for("flatpage", path="email_sent"))
@ -264,7 +264,7 @@ def handle_set_password(form):
user_by_email = User.query.filter_by(email=form.email.data).first() user_by_email = User.query.filter_by(email=form.email.data).first()
if user_by_email: if user_by_email:
send_anon_email.delay(form.email.data, "Email already in use", send_anon_email.delay(form.email.data, gettext("Email already in use"),
gettext(u"We were unable to create the account as the email is already in use by %(display_name)s. Try a different email address.", gettext(u"We were unable to create the account as the email is already in use by %(display_name)s. Try a different email address.",
display_name=user_by_email.display_name)) display_name=user_by_email.display_name))
else: else:

@ -16,22 +16,22 @@ def get_setting_tabs(user):
return [ return [
{ {
"id": "edit_profile", "id": "edit_profile",
"title": "Edit Profile", "title": gettext("Edit Profile"),
"url": url_for("users.profile_edit", username=user.username) "url": url_for("users.profile_edit", username=user.username)
}, },
{ {
"id": "account", "id": "account",
"title": "Account and Security", "title": gettext("Account and Security"),
"url": url_for("users.account", username=user.username) "url": url_for("users.account", username=user.username)
}, },
{ {
"id": "notifications", "id": "notifications",
"title": "Email and Notifications", "title": gettext("Email and Notifications"),
"url": url_for("users.email_notifications", username=user.username) "url": url_for("users.email_notifications", username=user.username)
}, },
{ {
"id": "api_tokens", "id": "api_tokens",
"title": "API Tokens", "title": gettext("API Tokens"),
"url": url_for("api.list_tokens", username=user.username) "url": url_for("api.list_tokens", username=user.username)
}, },
] ]
@ -130,7 +130,7 @@ def handle_email_notifications(user, prefs: UserNotificationPreferences, is_new,
newEmail = form.email.data newEmail = form.email.data
if newEmail and newEmail != user.email and newEmail.strip() != "": if newEmail and newEmail != user.email and newEmail.strip() != "":
if EmailSubscription.query.filter_by(email=form.email.data, blacklisted=True).count() > 0: if EmailSubscription.query.filter_by(email=form.email.data, blacklisted=True).count() > 0:
flash("That email address has been unsubscribed/blacklisted, and cannot be used", "danger") flash(gettext("That email address has been unsubscribed/blacklisted, and cannot be used"), "danger")
return return
token = randomString(32) token = randomString(32)