From ab3055b11c4a573922f069931a25c4c42eefe2f7 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Tue, 26 Mar 2024 22:55:53 +0000 Subject: [PATCH 1/5] feat(enrollment): success page displays expiration date if any with the TIME_ZONE='America/Los_Angeles' setting, Django will display the expiration date in that time zone Django automatically formats the date according to the user's locale (e.g. 'en' or 'es') turned off djlint around this section because the different

tags in branches of the {% if %} block was throwing errors and causing weird formatting" --- .../enrollment/templates/enrollment/success.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/benefits/enrollment/templates/enrollment/success.html b/benefits/enrollment/templates/enrollment/success.html index 71b8cf5fa..c5a90c58d 100644 --- a/benefits/enrollment/templates/enrollment/success.html +++ b/benefits/enrollment/templates/enrollment/success.html @@ -21,10 +21,17 @@

{% translate "Success! Your transit benefit is now conn
-

- {% block success-message %} - {% endblock success-message %} -

+ {# djlint:off #} + {% if enrollment.supports_expiration %} +

{% translate "Your benefit will expire on" %} {{ enrollment.expires|date }}.

+

+ {% else %} +

+ {% endif %} + {% block success-message %} + {% endblock success-message %} +

+ {# djlint:on #}

{% translate "Thank you for using Cal-ITP Benefits!" %}

From 01c52c92f1bfeb63a3f884178fcfa8cb46c12fc4 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Thu, 28 Mar 2024 22:33:38 +0000 Subject: [PATCH 2/5] style: desktop spacing on enrollment success align with the 8-point grid and updated comps in Figma --- benefits/enrollment/templates/enrollment/success.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benefits/enrollment/templates/enrollment/success.html b/benefits/enrollment/templates/enrollment/success.html index c5a90c58d..f4b161840 100644 --- a/benefits/enrollment/templates/enrollment/success.html +++ b/benefits/enrollment/templates/enrollment/success.html @@ -13,7 +13,7 @@ {% block headline %}
-

{% translate "Success! Your transit benefit is now connected to your card." %}

+

{% translate "Success! Your transit benefit is now connected to your card." %}

{% endblock headline %} @@ -23,7 +23,7 @@

{% translate "Success! Your transit benefit is now conn
{# djlint:off #} {% if enrollment.supports_expiration %} -

{% translate "Your benefit will expire on" %} {{ enrollment.expires|date }}.

+

{% translate "Your benefit will expire on" %} {{ enrollment.expires|date }}.

{% else %}

From cb42683b8ac2dbba7bc85cb4add649ce6f1dd698 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Fri, 26 Apr 2024 16:51:29 +0000 Subject: [PATCH 3/5] feat(i18n): custom date formats per locale see https://docs.djangoproject.com/en/5.0/topics/i18n/formatting/#creating-custom-format-files --- benefits/locale/__init__.py | 0 benefits/locale/en/__init__.py | 0 benefits/locale/en/formats.py | 2 ++ benefits/locale/es/__init__.py | 0 benefits/locale/es/formats.py | 5 +++++ benefits/settings.py | 5 +++++ 6 files changed, 12 insertions(+) create mode 100644 benefits/locale/__init__.py create mode 100644 benefits/locale/en/__init__.py create mode 100644 benefits/locale/en/formats.py create mode 100644 benefits/locale/es/__init__.py create mode 100644 benefits/locale/es/formats.py diff --git a/benefits/locale/__init__.py b/benefits/locale/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/benefits/locale/en/__init__.py b/benefits/locale/en/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/benefits/locale/en/formats.py b/benefits/locale/en/formats.py new file mode 100644 index 000000000..fbe2609bc --- /dev/null +++ b/benefits/locale/en/formats.py @@ -0,0 +1,2 @@ +# https://docs.djangoproject.com/en/5.0/ref/templates/builtins/#date-and-time-formatting-specifiers +DATE_FORMAT = "F j, Y" diff --git a/benefits/locale/es/__init__.py b/benefits/locale/es/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/benefits/locale/es/formats.py b/benefits/locale/es/formats.py new file mode 100644 index 000000000..86e0c3fdb --- /dev/null +++ b/benefits/locale/es/formats.py @@ -0,0 +1,5 @@ +# Both “d” and “e” are backslash-escaped, because otherwise each is a format string +# that displays the day and the timezone name, respectively. +# Instead we want the literal word "de" +# https://docs.djangoproject.com/en/5.0/ref/templates/builtins/#date-and-time-formatting-specifiers +DATE_FORMAT = r"j \d\e F \d\e Y" diff --git a/benefits/settings.py b/benefits/settings.py index c1ad706c0..2d72dc8d2 100644 --- a/benefits/settings.py +++ b/benefits/settings.py @@ -207,6 +207,11 @@ def RUNTIME_ENVIRONMENT(): TIME_ZONE = "UTC" USE_TZ = True +# https://docs.djangoproject.com/en/5.0/topics/i18n/formatting/#creating-custom-format-files +FORMAT_MODULE_PATH = [ + "benefits.locale", +] + # Static files (CSS, JavaScript, Images) STATIC_URL = "/static/" From 77e9e6594eff648b1a45b344a4c579a9bd915af7 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Fri, 26 Apr 2024 16:58:43 +0000 Subject: [PATCH 4/5] fix(i18n): add missing strings --- benefits/locale/en/LC_MESSAGES/django.po | 5 ++++- benefits/locale/es/LC_MESSAGES/django.po | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/benefits/locale/en/LC_MESSAGES/django.po b/benefits/locale/en/LC_MESSAGES/django.po index 4855c4e2e..b64c217d4 100644 --- a/benefits/locale/en/LC_MESSAGES/django.po +++ b/benefits/locale/en/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: https://github.com/cal-itp/benefits/issues \n" -"POT-Creation-Date: 2024-04-25 14:33-0700\n" +"POT-Creation-Date: 2024-04-26 16:57+0000\n" "Language: English\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -637,6 +637,9 @@ msgstr "" msgid "Success! Your transit benefit is now connected to your card." msgstr "" +msgid "Your benefit will expire on" +msgstr "" + msgid "Thank you for using Cal-ITP Benefits!" msgstr "" diff --git a/benefits/locale/es/LC_MESSAGES/django.po b/benefits/locale/es/LC_MESSAGES/django.po index c7841b5bd..71ace160e 100644 --- a/benefits/locale/es/LC_MESSAGES/django.po +++ b/benefits/locale/es/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: https://github.com/cal-itp/benefits/issues \n" -"POT-Creation-Date: 2024-04-25 14:33-0700\n" +"POT-Creation-Date: 2024-04-26 16:57+0000\n" "Language: Español\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -763,6 +763,9 @@ msgstr "Éxito" msgid "Success! Your transit benefit is now connected to your card." msgstr "¡Éxito! Su beneficio de tránsito ahora está conectado a su tarjeta." +msgid "Your benefit will expire on" +msgstr "" + msgid "Thank you for using Cal-ITP Benefits!" msgstr "¡Gracias por usar Cal-ITP Benefits!" From 9cdacdcf8e9768ec6e8e92895c57417195ad6be4 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Mon, 29 Apr 2024 19:37:40 +0000 Subject: [PATCH 5/5] test(locale): DATE_FORMAT results in expected str adding a few init files here to get test discovery to work with the new locale directories --- tests/__init__.py | 0 tests/pytest/__init__.py | 0 tests/pytest/locale/__init__.py | 0 tests/pytest/locale/test_formats.py | 36 +++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/pytest/__init__.py create mode 100644 tests/pytest/locale/__init__.py create mode 100644 tests/pytest/locale/test_formats.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/pytest/__init__.py b/tests/pytest/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/pytest/locale/__init__.py b/tests/pytest/locale/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/pytest/locale/test_formats.py b/tests/pytest/locale/test_formats.py new file mode 100644 index 000000000..77499a42d --- /dev/null +++ b/tests/pytest/locale/test_formats.py @@ -0,0 +1,36 @@ +from datetime import datetime + +import pytest + +from django.utils.formats import date_format + +from benefits.locale.en.formats import DATE_FORMAT as DATE_FORMAT_EN +from benefits.locale.es.formats import DATE_FORMAT as DATE_FORMAT_ES + + +@pytest.fixture +def date_december(): + return datetime(2024, 12, 1) + + +@pytest.fixture +def date_march(): + return datetime(2024, 3, 1) + + +def test_en_DATE_FORMAT_december(date_december): + assert date_format(date_december, DATE_FORMAT_EN) == "December 1, 2024" + + +def test_en_DATE_FORMAT_march(date_march): + assert date_format(date_march, DATE_FORMAT_EN) == "March 1, 2024" + + +def test_es_DATE_FORMAT_december(settings, date_december): + settings.LANGUAGE_CODE = "es" + assert date_format(date_december, DATE_FORMAT_ES) == "1 de diciembre de 2024" + + +def test_es_DATE_FORMAT_march(settings, date_march): + settings.LANGUAGE_CODE = "es" + assert date_format(date_march, DATE_FORMAT_ES) == "1 de marzo de 2024"