Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix translations unparsable by Django's extractor #1905

Merged
merged 4 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion judge/jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from judge.highlight_code import highlight_code
from judge.user_translations import gettext
from . import (camo, datetime, filesize, gravatar, language, markdown, rating, reference, render, social,
from . import (camo, datetime, filesize, format, gravatar, language, markdown, rating, reference, render, social,
spaceless, submission, timedelta)
from . import registry

Expand Down
8 changes: 8 additions & 0 deletions judge/jinja2/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.utils.html import format_html

from . import registry


@registry.function
def bold(text):
return format_html('<b>{0}</b>', text)
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<a href="{{ url('user_page') }}">
<span>
<img src="{{ gravatar(request.user, 32) }}" height="24" width="24">{# -#}
<span>{{ _('Hello, %(username)s.', username=('<b>%s</b>'|safe|format(request.profile.display_name))) }}</span>
<span>{{ _('Hello, %(username)s.', username=bold(request.profile.display_name)) }}</span>
</span>
</a>
<ul style="width: 150px">
Expand Down
20 changes: 10 additions & 10 deletions templates/contest/contest.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@
{%- endif -%}
</a>
<div id="time">
{% if contest.time_limit %}
{{ _('%(time_limit)s window between %(start_time)s and %(end_time)s',
start_time='<b>%s</b>'|safe|format(contest.start_time|date(_("F j, Y, G:i T"))),
end_time='<b>%s</b>'|safe|format(contest.end_time|date(_("F j, Y, G:i T"))),
time_limit='<b>%s</b>'|safe|format(contest.time_limit|timedelta('localized-no-seconds'))) }}
{% else %}
{{ _('%(length)s long starting on %(start_time)s',
start_time='<b>%s</b>'|safe|format(contest.start_time|date(_("F j, Y, G:i T"))),
length='<b>%s</b>'|safe|format(contest.contest_window_length|timedelta('localized-no-seconds'))) }}
{% endif %}
{% with start_time=contest.start_time|date(_("F j, Y, G:i T")) %}
{% if contest.time_limit %}
{% set end_time=contest.end_time|date(_("F j, Y, G:i T")) %}
{% set time_limit=contest.time_limit|timedelta('localized-no-seconds') %}
{{ _('%(time_limit)s window between %(start_time)s and %(end_time)s', start_time=bold(start_time), end_time=bold(end_time), time_limit=bold(time_limit)) }}
{% else %}
{% set length=contest.contest_window_length|timedelta('localized-no-seconds') %}
{{ _('%(length)s long starting on %(start_time)s', start_time=bold(start_time), length=bold(length)) }}
{% endif %}
{% endwith %}
</div>
{% if contest.show_short_display %}
<div id="details">
Expand Down
3 changes: 1 addition & 2 deletions templates/problem/submit.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@
<div class="alert alert-warning alert-dismissable">
<a class="close">x</a>
<b>{{ _('Warning!') }}</b>
{{ _('Your default language, %(language)s, is unavailable for this problem and has been deselected.',
language='<b>%s</b>'|safe|format(default_lang.name)) }}
{{ _('Your default language, %(language)s, is unavailable for this problem and has been deselected.', language=bold(default_lang.name)) }}
</div>
{% endif %}

Expand Down
4 changes: 2 additions & 2 deletions templates/registration/password_change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<div class="centered-form">
<form action="" method="post" class="form-area">
{% if request.session.password_pwned %}
<h4>{{ _('We found your password in <a href="https://haveibeenpwned.com/Passwords">a database of compromised passwords</a>.
To protect your account, we are requiring you to change your password to a more secure password.') }}</h4>
<h4>{{ (_('We found your password in [a database of compromised passwords][0].') + '\n\n [0]: https://haveibeenpwned.com/Passwords')|markdown('default', strip_paragraphs=True) }}
{{ _('To protect your account, we are requiring you to change your password to a more secure password.') }}</h4>
{% endif %}
{% csrf_token %}
<table border="0" class="django-as-table">{{ form.as_table() }}</table>
Expand Down
9 changes: 5 additions & 4 deletions templates/submission/status-testcases.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ <h3>{{ _('Execution Results') }}</h3>
{{ submission.case_points|floatformat(0) }}/{{ submission.case_total|floatformat(0) }}
{% if request.in_contest and submission.contest_or_none %}
{% with contest=submission.contest_or_none %}
({{ _('%(points)s/%(total)s points', points=contest.points|roundfloat(3),
total=contest.problem.points|floatformat(-1)) }})
{% set points=contest.points|roundfloat(3) %}
{% set total=contest.problem.points|floatformat(-1) %}
({{ _('%(points)s/%(total)s points', points=points, total=total) }})
{% endwith %}
{% else %}
({{ _('%(points)s/%(total)s points', points=submission.points|roundfloat(3),
total=submission.problem.points|floatformat(-1)) }})
{% with points=submission.points|roundfloat(3), total=submission.problem.points|floatformat(-1) %}
({{ _('%(points)s/%(total)s points', points=points, total=total) }})
{% endif %}
{% if is_pretest and submission.result == "AC" %}
<br>
Expand Down