Pull markup out of translation files

it's bad enough that we do markup in views.py

See #161
This commit is contained in:
Klaas van Schelven
2025-08-28 15:31:43 +02:00
parent a3cdeb9c8a
commit f38112f3df
3 changed files with 24 additions and 18 deletions

Binary file not shown.

View File

@@ -342,22 +342,23 @@ msgstr "超过此数量的事件将会被丢弃。"
msgid "DSN (read-only)" msgid "DSN (read-only)"
msgstr "DSN (只读)" msgstr "DSN (只读)"
#. Translators: {link} will be replaced with an HTML link; place it where it reads naturally.
#, python-brace-format
msgid "Use the DSN to {link}."
msgstr "使用 DSN 来{link}。"
#: projects/forms.py:103 #: projects/forms.py:103
#, python-format msgid "set up the SDK"
msgid "" msgstr "设置 SDK"
"Use the DSN to <a href=\"%s\" class=\"text-cyan-800 font-bold\">set up the "
"SDK</a>."
msgstr ""
"<a href=\"%s\" class=\"text-cyan-800 font-bold\">设置SDK</a>以使用DSN。"
#: projects/forms.py:115 #: projects/forms.py:115
#, fuzzy, python-format #. Translators: This text is followed by a clickable link. Adjust punctuation/spacing naturally.
msgid "" msgid "You don't have any teams yet; "
"You don't have any teams yet; <a href=\"%s\" class=\"text-cyan-800 font-" msgstr "你还没有任何团队;"
"bold\">Create a team first.</a>"
msgstr "" #: projects/forms.py:115
"你没有任何可用团队。<a href=\"%s\" class=\"text-cyan-800 font-bold\">创建一个" msgid "Create a team first."
"新团队。</a>" msgstr "先创建一个团队。"
#: projects/models.py:50 teams/models.py:9 #: projects/models.py:50 teams/models.py:9
msgid "Member" msgid "Member"

View File

@@ -4,6 +4,7 @@ from django.template.defaultfilters import yesno
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy from django.utils.translation import pgettext_lazy
from django.utils.html import format_html
from bugsink.utils import assert_ from bugsink.utils import assert_
from teams.models import TeamMembership from teams.models import TeamMembership
@@ -100,8 +101,11 @@ class ProjectForm(forms.ModelForm):
self.fields["dsn"].initial = self.instance.dsn self.fields["dsn"].initial = self.instance.dsn
self.fields["dsn"].label = _("DSN (read-only)") self.fields["dsn"].label = _("DSN (read-only)")
href = reverse('project_sdk_setup', kwargs={'project_pk': self.instance.pk}) href = reverse('project_sdk_setup', kwargs={'project_pk': self.instance.pk})
self.fields["dsn"].help_text = _(
"Use the DSN to <a href=\"%s\" class=\"text-cyan-800 font-bold\">set up the SDK</a>.") % href self.fields["dsn"].help_text = format_html(
_("Use the DSN to {link}."),
link=format_html('<a href="{}" class="text-cyan-800 font-bold">{}</a>', href, _("set up the SDK")),
)
# if we ever push slug to the form, editing it should probably be disallowed as well (but mainly because it # if we ever push slug to the form, editing it should probably be disallowed as well (but mainly because it
# has consequences on the issue's short identifier) # has consequences on the issue's short identifier)
@@ -113,9 +117,10 @@ class ProjectForm(forms.ModelForm):
self.fields["team"].queryset = team_qs self.fields["team"].queryset = team_qs
if team_qs.count() == 0: if team_qs.count() == 0:
href = reverse("team_new") href = reverse("team_new")
self.fields["team"].help_text = _( self.fields["team"].help_text = format_html(
'You don\'t have any teams yet; ' "{}{}", _("You don't have any teams yet; "),
'<a href="%s" class="text-cyan-800 font-bold">Create a team first.</a>') % href format_html('<a href="{}" class="text-cyan-800 font-bold">{}</a>', href, _("Create a team first.")))
elif team_qs.count() == 1: elif team_qs.count() == 1:
self.fields["team"].initial = team_qs.first() self.fields["team"].initial = team_qs.first()