diff --git a/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs b/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs index 97aa6ca3acc..9a32e3ff7fc 100644 --- a/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs +++ b/mon-pix/app/components/authentication/password-reset-demand/password-reset-demand-form.gjs @@ -16,6 +16,7 @@ import PasswordResetDemandReceivedInfo from './password-reset-demand-received-in export default class PasswordResetDemandForm extends Component { @service errors; @service requestManager; + @service url; @tracked globalError = this.errors.hasErrors && this.errors.shift(); @tracked isLoading = false; @@ -114,7 +115,7 @@ export default class PasswordResetDemandForm extends Component {

{{t "components.authentication.password-reset-demand-form.no-email-question"}}

- + {{t "components.authentication.password-reset-demand-form.contact-us-link.link-text"}}
diff --git a/mon-pix/app/services/locale.js b/mon-pix/app/services/locale.js index fe46a8ca822..999924845af 100644 --- a/mon-pix/app/services/locale.js +++ b/mon-pix/app/services/locale.js @@ -8,6 +8,8 @@ export const ENGLISH_INTERNATIONAL_LOCALE = 'en'; export const FRENCH_FRANCE_LOCALE = 'fr-FR'; export const DEFAULT_LOCALE = FRENCH_INTERNATIONAL_LOCALE; +const SUPPORTED_LOCALES = ['en', 'es', 'fr', 'fr-BE', 'fr-FR', 'nl-BE', 'nl']; + const supportedLanguages = Object.keys(languages); export default class LocaleService extends Service { @@ -16,6 +18,15 @@ export default class LocaleService extends Service { @service intl; @service dayjs; + isSupportedLocale(locale) { + try { + const localeCanonicalName = Intl.getCanonicalLocales(locale)?.[0]; + return SUPPORTED_LOCALES.some((supportedLocale) => localeCanonicalName == supportedLocale); + } catch { + return false; + } + } + handleUnsupportedLanguage(language) { if (!language) return; return supportedLanguages.includes(language) ? language : DEFAULT_LOCALE; diff --git a/mon-pix/app/services/url.js b/mon-pix/app/services/url.js index 75026abb261..d2df2859491 100644 --- a/mon-pix/app/services/url.js +++ b/mon-pix/app/services/url.js @@ -8,6 +8,7 @@ const SPANISH_INTERNATIONAL_LOCALE = 'es'; export default class Url extends Service { @service currentDomain; @service intl; + @service locale; definedHomeUrl = ENV.rootURL; @@ -108,22 +109,22 @@ export default class Url extends Service { } get supportHomeUrl() { - const currentLanguage = this.intl.primaryLocale; + const currentLocale = this.intl.primaryLocale; if (this.currentDomain.isFranceDomain) { return 'https://pix.fr/support'; } - switch (currentLanguage) { - case ENGLISH_INTERNATIONAL_LOCALE: - return 'https://pix.org/en/support'; - case DUTCH_INTERNATIONAL_LOCALE: - return 'https://pix.org/nl-be/support'; - case SPANISH_INTERNATIONAL_LOCALE: - return 'https://pix.org/en/support'; - default: - return 'https://pix.org/fr/support'; + let locale; + if (currentLocale == 'nl') { + locale = 'nl-BE'; + } else if (this.locale.isSupportedLocale(currentLocale)) { + locale = currentLocale; + } else { + locale = ENGLISH_INTERNATIONAL_LOCALE; } + + return `https://pix.org/${locale}/support`; } get serverStatusUrl() { diff --git a/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs b/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs index ad546fb2469..65a60e37692 100644 --- a/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs +++ b/mon-pix/tests/integration/components/authentication/password-reset-demand/password-reset-demand-form-test.gjs @@ -1,4 +1,5 @@ import { fillByLabel, render } from '@1024pix/ember-testing-library'; +import Service from '@ember/service'; import { click } from '@ember/test-helpers'; import { setLocale, t } from 'ember-intl/test-support'; import PasswordResetDemandForm from 'mon-pix/components/authentication/password-reset-demand/password-reset-demand-form'; @@ -30,6 +31,17 @@ module('Integration | Component | Authentication | PasswordResetDemand | passwor test('it displays all elements of component successfully', async function (assert) { // given + class CurrentDomainServiceStub extends Service { + get isFranceDomain() { + return true; + } + + getExtension() { + return '.fr'; + } + } + this.owner.register('service:currentDomain', CurrentDomainServiceStub); + const screen = await render(); // then diff --git a/mon-pix/tests/unit/services/locale-test.js b/mon-pix/tests/unit/services/locale-test.js index 753878c39b4..35f5d7e4718 100644 --- a/mon-pix/tests/unit/services/locale-test.js +++ b/mon-pix/tests/unit/services/locale-test.js @@ -27,6 +27,60 @@ module('Unit | Services | locale', function (hooks) { sinon.stub(intlService, 'setLocale'); }); + module('#isSupportedLocale', function () { + module('when locale is supported', function () { + test('returns true', function (assert) { + // given + const locale = 'nl-BE'; + + // when + const result = localeService.isSupportedLocale(locale); + + // then + assert.true(result); + }); + }); + + module('when locale is supported but not given in canonical form', function () { + test('returns true', function (assert) { + // given + const locale = 'nl-be'; + + // when + const result = localeService.isSupportedLocale(locale); + + // then + assert.true(result); + }); + }); + + module('when locale is valid but not supported', function () { + test('returns false', function (assert) { + // given + const locale = 'ko'; + + // when + const result = localeService.isSupportedLocale(locale); + + // then + assert.false(result); + }); + }); + + module('when locale is invalid', function () { + test('returns false', function (assert) { + // given + const locale = 'invalid_locale_in_bad_format'; + + // when + const result = localeService.isSupportedLocale(locale); + + // then + assert.false(result); + }); + }); + }); + module('#handleUnsupportedLanguage', function () { module('when language is not supported', function () { test('returns default language', function (assert) { diff --git a/mon-pix/tests/unit/services/url-test.js b/mon-pix/tests/unit/services/url-test.js index 67571274844..48189d7fd38 100644 --- a/mon-pix/tests/unit/services/url-test.js +++ b/mon-pix/tests/unit/services/url-test.js @@ -496,7 +496,7 @@ module('Unit | Service | url', function (hooks) { const service = this.owner.lookup('service:url'); service.currentDomain = { isFranceDomain: false }; service.intl = { primaryLocale: DUTCH_INTERNATIONAL_LOCALE }; - const expectedSupportHomeUrl = 'https://pix.org/nl-be/support'; + const expectedSupportHomeUrl = 'https://pix.org/nl-BE/support'; // when const supportHomeUrl = service.supportHomeUrl; diff --git a/mon-pix/translations/en.json b/mon-pix/translations/en.json index 5672c3e157d..3779555357f 100644 --- a/mon-pix/translations/en.json +++ b/mon-pix/translations/en.json @@ -184,8 +184,7 @@ "receive-reset-button": "Receive a reset link" }, "contact-us-link": { - "link-text": "Contact us", - "link-url": "https://pix.org/en/support" + "link-text": "Contact us" }, "fields": { "email": { diff --git a/mon-pix/translations/es.json b/mon-pix/translations/es.json index aa61086b9b5..3340a09e313 100644 --- a/mon-pix/translations/es.json +++ b/mon-pix/translations/es.json @@ -190,8 +190,7 @@ "receive-reset-button": "Reiniciar contraseña" }, "contact-us-link": { - "link-text": "Contáctanos.", - "link-url": "https://pix.fr/support" + "link-text": "Contáctanos." }, "fields": { "email": { diff --git a/mon-pix/translations/fr.json b/mon-pix/translations/fr.json index 5b7aa749f32..2824b6b4519 100644 --- a/mon-pix/translations/fr.json +++ b/mon-pix/translations/fr.json @@ -184,8 +184,7 @@ "receive-reset-button": "Recevoir un lien de réinitialisation" }, "contact-us-link": { - "link-text": "Contactez-nous", - "link-url": "https://pix.fr/support" + "link-text": "Contactez-nous" }, "fields": { "email": { diff --git a/mon-pix/translations/nl.json b/mon-pix/translations/nl.json index a17b8d621e1..0819f268276 100644 --- a/mon-pix/translations/nl.json +++ b/mon-pix/translations/nl.json @@ -190,8 +190,7 @@ "receive-reset-button": "Een reset-link ontvangen" }, "contact-us-link": { - "link-text": "Contacteer ons", - "link-url": "https://pix.fr/support" + "link-text": "Contacteer ons" }, "fields": { "email": {