Skip to content

Commit

Permalink
refactor newsletter-signup localization
Browse files Browse the repository at this point in the history
  • Loading branch information
robdivincenzo committed Apr 23, 2024
1 parent d68b335 commit 69d252c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SALESFORCE_COUNTRY_LIST from "../../petition/salesforce-country-list.js";
import { getText } from "../../petition/locales";

let countryDefault = { value: "", label: getText(`Your country`) };
let countryDefault = { value: "", label: gettext("Your country") };
let countryOptions = Object.keys(SALESFORCE_COUNTRY_LIST).map((code) => {
return {
value: code,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import { ReactGA } from "../../../common";
import { getText } from "../../petition/locales";

/**
* Higher-order component that handles form submission logic and validation
Expand All @@ -27,20 +26,20 @@ function withSubmissionLogic(WrappedComponent) {
this.validators = {
email: (value) => {
if (!value) {
return getText(`This is a required section.`);
return gettext("This is a required section.");
}

// Regex copied from join.jsx
const emailRegex = new RegExp(/[^@]+@[^.@]+(\.[^.@]+)+$/);
if (!emailRegex.test(value)) {
return getText(`Please enter a valid email address.`);
return gettext("Please enter a valid email address.");
}

return null;
},
privacy: (value) => {
if (value !== "true") {
return getText(`Please check this box if you want to proceed.`);
return gettext("Please check this box if you want to proceed.");
}
return null;
},
Expand Down Expand Up @@ -191,16 +190,16 @@ function withSubmissionLogic(WrappedComponent) {

if (res.status !== 201) {
this.setState({
apiError: getText(
`Something went wrong and your signup wasn't completed. Please try again later.`
apiError: gettext(
"Something went wrong and your signup wasn't completed. Please try again later."
),
});
throw new Error(res.statusText);
}
} catch (error) {
this.setState({
apiError: getText(
`Something went wrong and your signup wasn't completed. Please try again later.`
apiError: gettext(
"Something went wrong and your signup wasn't completed. Please try again later."
),
});
throw error;
Expand All @@ -219,7 +218,7 @@ function withSubmissionLogic(WrappedComponent) {
if (
this.state.apiSubmissionStatus === this.API_SUBMISSION_STATUS.SUCCESS
) {
message = getText(`Thanks!`);
message = gettext("Thanks!");
}

return message;
Expand All @@ -239,8 +238,8 @@ function withSubmissionLogic(WrappedComponent) {
) {
message = (
<>
<p>{getText(`confirm your email opt-in`)}</p>
<p>{getText(`manage your subscriptions`)}</p>
<p>{gettext("confirm your email opt-in")}</p>
<p>{gettext("manage your subscriptions")}</p>
</>
);
}
Expand Down

0 comments on commit 69d252c

Please sign in to comment.