From c8b0f9e6cee0e829bc3c758473068a0c810e4415 Mon Sep 17 00:00:00 2001
From: rubenwardy <rw@rubenwardy.com>
Date: Fri, 7 Jan 2022 22:11:12 +0000
Subject: [PATCH] Allow translating text in blueprints

---
 app/blueprints/packages/__init__.py | 15 ++++++++-------
 app/blueprints/packages/releases.py |  4 ++--
 app/blueprints/users/account.py     |  4 ++--
 app/blueprints/users/settings.py    | 10 +++++-----
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/app/blueprints/packages/__init__.py b/app/blueprints/packages/__init__.py
index a294af61..9af67622 100644
--- a/app/blueprints/packages/__init__.py
+++ b/app/blueprints/packages/__init__.py
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 from flask import Blueprint
+from flask_babel import gettext
 
 from app.models import User, Package, Permission
 
@@ -28,37 +29,37 @@ def get_package_tabs(user: User, package: Package):
 	return [
 		{
 			"id": "edit",
-			"title": "Edit Details",
+			"title": gettext("Edit Details"),
 			"url": package.getURL("packages.create_edit")
 		},
 		{
 			"id": "releases",
-			"title": "Releases",
+			"title": gettext("Releases"),
 			"url": package.getURL("packages.list_releases")
 		},
 		{
 			"id": "screenshots",
-			"title": "Screenshots",
+			"title": gettext("Screenshots"),
 			"url": package.getURL("packages.screenshots")
 		},
 		{
 			"id": "maintainers",
-			"title": "Maintainers",
+			"title": gettext("Maintainers"),
 			"url": package.getURL("packages.edit_maintainers")
 		},
 		{
 			"id": "audit",
-			"title": "Audit Log",
+			"title": gettext("Audit Log"),
 			"url": package.getURL("packages.audit")
 		},
 		{
 			"id": "share",
-			"title": "Share and Badges",
+			"title": gettext("Share and Badges"),
 			"url": package.getURL("packages.share")
 		},
 		{
 			"id": "remove",
-			"title": "Remove",
+			"title": gettext("Remove"),
 			"url": package.getURL("packages.remove")
 		}
 	]
diff --git a/app/blueprints/packages/releases.py b/app/blueprints/packages/releases.py
index 6ef7e64d..8b657da8 100644
--- a/app/blueprints/packages/releases.py
+++ b/app/blueprints/packages/releases.py
@@ -50,7 +50,7 @@ def get_mt_releases(is_max):
 
 class CreatePackageReleaseForm(FlaskForm):
 	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)
 	fileUpload = FileField(lazy_gettext("File Upload"))
 	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
 	form = CreatePackageReleaseForm()
 	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":
 			form["uploadOpt"].data = "vcs"
 			form.vcsLabel.data = request.args.get("ref")
diff --git a/app/blueprints/users/account.py b/app/blueprints/users/account.py
index c3aaa3f6..5679c9cf 100644
--- a/app/blueprints/users/account.py
+++ b/app/blueprints/users/account.py
@@ -137,7 +137,7 @@ def handle_register(form):
 
 	user_by_email = User.query.filter_by(email=form.email.data).first()
 	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.",
 					display_name=user_by_email.display_name))
 		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()
 			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.",
 							display_name=user_by_email.display_name))
 			else:
diff --git a/app/blueprints/users/settings.py b/app/blueprints/users/settings.py
index 4e5b2467..f5e2e873 100644
--- a/app/blueprints/users/settings.py
+++ b/app/blueprints/users/settings.py
@@ -16,22 +16,22 @@ def get_setting_tabs(user):
 	return [
 		{
 			"id": "edit_profile",
-			"title": "Edit Profile",
+			"title": gettext("Edit Profile"),
 			"url": url_for("users.profile_edit", username=user.username)
 		},
 		{
 			"id": "account",
-			"title": "Account and Security",
+			"title": gettext("Account and Security"),
 			"url": url_for("users.account", username=user.username)
 		},
 		{
 			"id": "notifications",
-			"title": "Email and Notifications",
+			"title": gettext("Email and Notifications"),
 			"url": url_for("users.email_notifications", username=user.username)
 		},
 		{
 			"id": "api_tokens",
-			"title": "API Tokens",
+			"title": gettext("API Tokens"),
 			"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
 		if newEmail and newEmail != user.email and newEmail.strip() != "":
 			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
 
 			token = randomString(32)