From 0c63366cee8aeb7eb57c6165b7cb84414b7984e3 Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Fri, 17 May 2024 08:37:40 -0400 Subject: [PATCH 1/6] Update retirement app to standard /es/ prefix and add language picker to the about page --- cfgov/cfgov/urls.py | 4 +++ cfgov/retirement_api/es_urls.py | 33 +++++++++++++++++++ .../jinja2/retirement_api/about.html | 13 ++++++++ .../jinja2/retirement_api/claiming.html | 7 ++-- cfgov/retirement_api/tests/test_views.py | 8 ++--- cfgov/retirement_api/urls.py | 27 ++------------- .../apps/retirement/js/data/index.js | 9 ++--- .../apps/retirement/js/views/graph-view.js | 3 +- 8 files changed, 63 insertions(+), 41 deletions(-) create mode 100644 cfgov/retirement_api/es_urls.py diff --git a/cfgov/cfgov/urls.py b/cfgov/cfgov/urls.py index becaede1d44..eec23d093de 100644 --- a/cfgov/cfgov/urls.py +++ b/cfgov/cfgov/urls.py @@ -247,6 +247,10 @@ def empty_200_response(request, *args, **kwargs): r"^consumer-tools/retirement/", include("retirement_api.urls", namespace="retirement_api"), ), + re_path( + r"^es/herramientas-del-consumidor/jubilacion/", + include("retirement_api.es_urls", namespace="retirement_api_es"), + ), # CCDB5-API re_path( r"^data-research/consumer-complaints/search/api/v1/", diff --git a/cfgov/retirement_api/es_urls.py b/cfgov/retirement_api/es_urls.py new file mode 100644 index 00000000000..39f50fb21f3 --- /dev/null +++ b/cfgov/retirement_api/es_urls.py @@ -0,0 +1,33 @@ +from core.views import TranslatedTemplateView +from retirement_api.views import estimator + + +try: + from django.urls import re_path +except ImportError: + from django.conf.urls import url as re_path + +app_name = "retirement_api_es" + +urlpatterns = [ + re_path( + r"^before-you-claim/mas-sobre/$", + TranslatedTemplateView.as_view( + template_name="retirement_api/about.html", language="es" + ), + name="about", + ), + re_path( + r"^antes-de-solicitar/$", + TranslatedTemplateView.as_view( + template_name="retirement_api/claiming-es.html", language="es" + ), + name="claiming", + ), + re_path( + r"^retirement-api/estimator/(?P[^/]+)/(?P\d+)/$", + estimator, + {"language": "es"}, + name="estimator", + ), +] diff --git a/cfgov/retirement_api/jinja2/retirement_api/about.html b/cfgov/retirement_api/jinja2/retirement_api/about.html index 570b1a543c9..41e6e4651fe 100644 --- a/cfgov/retirement_api/jinja2/retirement_api/about.html +++ b/cfgov/retirement_api/jinja2/retirement_api/about.html @@ -12,6 +12,19 @@

{{ _("Planning your Social Security claiming age") }}

+ {% import 'v1/includes/molecules/translation-links.html' as translation_links with context %} + {{ translation_links.render( + links=[ + { + 'href': url('retirement_api_en:about'), + 'language': 'en', + 'text': 'English' + },{ + 'href': url('retirement_api_es:about'), + 'language': 'es', + 'text': 'Spanish' + }] + ) }}

{{ _("How do we generate your estimates?") }}

diff --git a/cfgov/retirement_api/jinja2/retirement_api/claiming.html b/cfgov/retirement_api/jinja2/retirement_api/claiming.html index f7d0adae806..7024d8e3e2f 100644 --- a/cfgov/retirement_api/jinja2/retirement_api/claiming.html +++ b/cfgov/retirement_api/jinja2/retirement_api/claiming.html @@ -31,16 +31,15 @@

{{ _("Planning your Social Security claiming age") }}

{{ _("The age you claim Social Security affects your lifetime income. We’ll help you think through this decision.") }}

- {% import 'v1/includes/molecules/translation-links.html' as translation_links with context %} {{ translation_links.render( links=[ { - 'href': '../', + 'href': url('retirement_api_en:claiming'), 'language': 'en', 'text': 'English' },{ - 'href': 'es/', + 'href': url('retirement_api_es:claiming'), 'language': 'es', 'text': 'Spanish' }] @@ -194,7 +193,7 @@

{{ _("About your early benefit claiming age:") }}

- {{ _("Where do these numbers come from?") }} diff --git a/cfgov/retirement_api/tests/test_views.py b/cfgov/retirement_api/tests/test_views.py index f4e270cec2c..abd2eb76b63 100644 --- a/cfgov/retirement_api/tests/test_views.py +++ b/cfgov/retirement_api/tests/test_views.py @@ -48,10 +48,10 @@ class ViewTests(TestCase): return_keys = ["data", "error"] def test_base_view(self): - url = reverse("retirement_api:claiming_en") + url = reverse("retirement_api_en:claiming") response = self.client.get(url) self.assertTrue(response.status_code == 200) - url = reverse("retirement_api:claiming_es") + url = reverse("retirement_api_en:claiming") response = self.client.get(url) self.assertTrue(response.status_code == 200) @@ -127,9 +127,9 @@ def test_estimator_query_data_bad_income(self): self.assertTrue(response.status_code == 400) def test_about_pages(self): - url = reverse("retirement_api:retirement_about_en") + url = reverse("retirement_api_en:retirement_about") response = self.client.get(url) self.assertTrue(response.status_code == 200) - url = reverse("retirement_api:retirement_about_es") + url = reverse("retirement_api_es:retirement_about") response = self.client.get(url) self.assertTrue(response.status_code == 200) diff --git a/cfgov/retirement_api/urls.py b/cfgov/retirement_api/urls.py index 8d1b75981b7..d538c1f0dd8 100644 --- a/cfgov/retirement_api/urls.py +++ b/cfgov/retirement_api/urls.py @@ -7,8 +7,7 @@ except ImportError: from django.conf.urls import url as re_path - -app_name = "retirement_api" +app_name = "retirement_api_en" urlpatterns = [ re_path( @@ -16,38 +15,18 @@ TranslatedTemplateView.as_view( template_name="retirement_api/about.html", language="en" ), - name="retirement_about_en", - ), - re_path( - r"^before-you-claim/about/es/$", - TranslatedTemplateView.as_view( - template_name="retirement_api/about.html", language="es" - ), - name="retirement_about_es", + name="about", ), re_path( r"^before-you-claim/$", TranslatedTemplateView.as_view( template_name="retirement_api/claiming.html", language="en" ), - name="claiming_en", - ), - re_path( - r"^before-you-claim/es/$", - TranslatedTemplateView.as_view( - template_name="retirement_api/claiming-es.html", language="es" - ), - name="claiming_es", + name="claiming", ), re_path( r"^retirement-api/estimator/(?P[^/]+)/(?P\d+)/$", estimator, name="estimator", ), - re_path( - r"^retirement-api/estimator/(?P[^/]+)/(?P\d+)/es/$", - estimator, - {"language": "es"}, - name="estimator_es", - ), ] diff --git a/cfgov/unprocessed/apps/retirement/js/data/index.js b/cfgov/unprocessed/apps/retirement/js/data/index.js index 9b784f1657e..ac3412e9383 100644 --- a/cfgov/unprocessed/apps/retirement/js/data/index.js +++ b/cfgov/unprocessed/apps/retirement/js/data/index.js @@ -20,17 +20,12 @@ export let lifetime = {}; /** * @param {string} birthdate - Birthday in MM-DD-YYYY format * @param {number} salary - Entered salary as a number - * @param {string} dataLang - Language * @returns {Promise} A promise that resolved to the parsed response */ -export function fetchApiData(birthdate, salary, dataLang) { +export function fetchApiData(birthdate, salary) { if (typeof birthdate !== 'string' || typeof salary !== 'number') throw new Error('Invalid API call'); - let url = `../retirement-api/estimator/${birthdate}/${salary}/`; - - if (dataLang === 'es') { - url = `../${url}es/`; - } + const url = `../retirement-api/estimator/${birthdate}/${salary}/`; return fetch(url).then((v) => v.json()); } diff --git a/cfgov/unprocessed/apps/retirement/js/views/graph-view.js b/cfgov/unprocessed/apps/retirement/js/views/graph-view.js index d392236eb0b..0e33fe9c6ea 100644 --- a/cfgov/unprocessed/apps/retirement/js/views/graph-view.js +++ b/cfgov/unprocessed/apps/retirement/js/views/graph-view.js @@ -241,7 +241,6 @@ function validateBirthdayFields() { * using a variety of view-updating functions. */ function getYourEstimates() { - const dataLang = document.querySelector('html').getAttribute('lang'); const dates = validateBirthdayFields(); const salaryInputElm = document.querySelector('#salary-input'); const salary = convertStringToNumber(salaryInputElm.value); @@ -251,7 +250,7 @@ function getYourEstimates() { highlightAgeFields(false); const loadIndDom = document.querySelector('#api-data-loading-indicator'); loadIndDom.style.display = 'inline-block'; - fetchApiData(dates.concat, salary, dataLang).then((resp) => { + fetchApiData(dates.concat, salary).then((resp) => { if (resp.error === '') { updateDataFromApi(resp); $('.step-two .question').css('display', 'inline-block'); From c097ab3ebac8e347525fb1f74fc1482fab102b97 Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Fri, 17 May 2024 08:46:54 -0400 Subject: [PATCH 2/6] Update redirects --- cfgov/apache/conf.d/redirects.conf | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cfgov/apache/conf.d/redirects.conf b/cfgov/apache/conf.d/redirects.conf index ee6a120816e..d264a7d7d86 100644 --- a/cfgov/apache/conf.d/redirects.conf +++ b/cfgov/apache/conf.d/redirects.conf @@ -252,12 +252,13 @@ RedirectMatch permanent (.*)/realestateprofessionals(.*) $1/real-estate-profess RedirectMatch permanent ^/real-estate[/]?$ /know-before-you-owe/real-estate-professionals/ # Retirement redirects -RedirectMatch permanent (?i)^/retirement/claiming-social-security/?$ /retirement/before-you-claim/ -RedirectMatch permanent (?i)^/jubilacion/?$ /retirement/before-you-claim/es/ -RedirectMatch permanent (?i)^/retirement/?$ /retirement/before-you-claim/ +RedirectMatch permanent (?i)^/retirement/claiming-social-security/?$ /consumer-tools/retirement/before-you-claim/ +RedirectMatch permanent (?i)^/jubilacion/?$ /es/herramientas-del-consumidor/jubilacion/antes-de-solicitar/ +RedirectMatch permanent (?i)^/retirement/?$ /consumer-tools/retirement/before-you-claim/ # Redirect from /es/ suffix urls RedirectMatch permanent (?i)^/consumer-tools/financial-well-being/es/ /es/herramientas-del-consumidor/bienestar-financiero/ +RedirectMatch permanent (?i)^/consumer-tools/retirement/before-you-claim/es/ /es/herramientas-del-consumidor/jubilacion/antes-de-solicitar/ # Owning a Home redirects RewriteRule ^owningahome$ /owning-a-home$1 [L,R=301] From 7bd3591d2c8fb1464e4bafd80d42aebba1dd05dd Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Fri, 17 May 2024 08:50:19 -0400 Subject: [PATCH 3/6] Lean on namespace for reverse --- cfgov/retirement_api/tests/test_views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cfgov/retirement_api/tests/test_views.py b/cfgov/retirement_api/tests/test_views.py index abd2eb76b63..5f27bf156c6 100644 --- a/cfgov/retirement_api/tests/test_views.py +++ b/cfgov/retirement_api/tests/test_views.py @@ -127,9 +127,9 @@ def test_estimator_query_data_bad_income(self): self.assertTrue(response.status_code == 400) def test_about_pages(self): - url = reverse("retirement_api_en:retirement_about") + url = reverse("retirement_api_en:about") response = self.client.get(url) self.assertTrue(response.status_code == 200) - url = reverse("retirement_api_es:retirement_about") + url = reverse("retirement_api_es:about") response = self.client.get(url) self.assertTrue(response.status_code == 200) From 07a0b38f1a5865289e6e2444bbdb8603d3703a33 Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Fri, 17 May 2024 09:42:36 -0400 Subject: [PATCH 4/6] fix spanish url in cypress --- .../consumer-tools/before-you-claim/before-you-claim.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cypress/integration/consumer-tools/before-you-claim/before-you-claim.cy.js b/test/cypress/integration/consumer-tools/before-you-claim/before-you-claim.cy.js index a30fd50104f..ca8ba9ab616 100644 --- a/test/cypress/integration/consumer-tools/before-you-claim/before-you-claim.cy.js +++ b/test/cypress/integration/consumer-tools/before-you-claim/before-you-claim.cy.js @@ -24,7 +24,7 @@ describe('Planning your Social Security', () => { //*******************************************/ //**********Language Selection***************/ it('should have a spanish view', () => { - cy.intercept('/consumer-tools/retirement/before-you-claim/es').as( + cy.intercept('/es/consumer-tools/retirement/before-you-claim/').as( 'getSpanish', ); claim.setLanguageToSpanish(); From 83127ccbbf9a1264dfac257c161efe16504bd742 Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Fri, 17 May 2024 10:08:47 -0400 Subject: [PATCH 5/6] Actual spanish url for cypress --- .../consumer-tools/before-you-claim/before-you-claim.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cypress/integration/consumer-tools/before-you-claim/before-you-claim.cy.js b/test/cypress/integration/consumer-tools/before-you-claim/before-you-claim.cy.js index ca8ba9ab616..f4ae0d701c5 100644 --- a/test/cypress/integration/consumer-tools/before-you-claim/before-you-claim.cy.js +++ b/test/cypress/integration/consumer-tools/before-you-claim/before-you-claim.cy.js @@ -24,7 +24,7 @@ describe('Planning your Social Security', () => { //*******************************************/ //**********Language Selection***************/ it('should have a spanish view', () => { - cy.intercept('/es/consumer-tools/retirement/before-you-claim/').as( + cy.intercept('/es/herramientas-del-consumidor/jubilacion/antes-de-solicitar/').as( 'getSpanish', ); claim.setLanguageToSpanish(); From e291951d348f0b432f8fe7707a4e89f35d52c93e Mon Sep 17 00:00:00 2001 From: Wyatt Pearsall Date: Fri, 17 May 2024 10:47:04 -0400 Subject: [PATCH 6/6] remove dup redirect --- cfgov/apache/conf.d/redirects.conf | 3 --- 1 file changed, 3 deletions(-) diff --git a/cfgov/apache/conf.d/redirects.conf b/cfgov/apache/conf.d/redirects.conf index d277189eeb3..d264a7d7d86 100644 --- a/cfgov/apache/conf.d/redirects.conf +++ b/cfgov/apache/conf.d/redirects.conf @@ -260,9 +260,6 @@ RedirectMatch permanent (?i)^/retirement/?$ /consumer-tools/retirement/before-y RedirectMatch permanent (?i)^/consumer-tools/financial-well-being/es/ /es/herramientas-del-consumidor/bienestar-financiero/ RedirectMatch permanent (?i)^/consumer-tools/retirement/before-you-claim/es/ /es/herramientas-del-consumidor/jubilacion/antes-de-solicitar/ -# Redirect from /es/ suffix urls -RedirectMatch permanent (?i)^/consumer-tools/financial-well-being/es/ /es/herramientas-del-consumidor/bienestar-financiero/ - # Owning a Home redirects RewriteRule ^owningahome$ /owning-a-home$1 [L,R=301]