11/* eslint-disable */
2+ import i18n from 'i18next' ;
23export const domOnlyProps = ( {
34 initialValue,
45 autofill,
@@ -20,19 +21,19 @@ const EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))
2021
2122function validateNameEmail ( formProps , errors ) {
2223 if ( ! formProps . username ) {
23- errors . username = 'Please enter a username.' ;
24+ errors . username = i18n . t ( 'ReduxFormUtils.errorEmptyUsername' ) ;
2425 } else if ( ! formProps . username . match ( / ^ .{ 1 , 20 } $ / ) ) {
25- errors . username = 'Username must be less than 20 characters.' ;
26+ errors . username = i18n . t ( 'ReduxFormUtils.errorLongUsername' ) ;
2627 } else if ( ! formProps . username . match ( / ^ [ a - z A - Z 0 - 9 . _ - ] { 1 , 20 } $ / ) ) {
27- errors . username = 'Username must only consist of numbers, letters, periods, dashes, and underscores.' ;
28+ errors . username = i18n . t ( 'ReduxFormUtils.errorValidUsername' ) ;
2829 }
2930
3031 if ( ! formProps . email ) {
31- errors . email = 'Please enter an email.' ;
32+ errors . email = i18n . t ( 'ReduxFormUtils.errorEmptyEmail' ) ;
3233 } else if (
3334 // eslint-disable-next-line max-len
3435 ! formProps . email . match ( EMAIL_REGEX ) ) {
35- errors . email = 'Please enter a valid email address.' ;
36+ errors . email = i18n . t ( 'ReduxFormUtils.errorInvalidEmail' ) ;
3637 }
3738}
3839
@@ -42,21 +43,21 @@ export function validateSettings(formProps) {
4243 validateNameEmail ( formProps , errors ) ;
4344
4445 if ( formProps . currentPassword && ! formProps . newPassword ) {
45- errors . newPassword = 'Please enter a new password or leave the current password empty.' ;
46+ errors . newPassword = i18n . t ( 'ReduxFormUtils.errorNewPassword' ) ;
4647 }
4748 if ( formProps . newPassword && formProps . newPassword . length < 6 ) {
48- errors . newPassword = 'Password must be at least 6 characters' ;
49+ errors . newPassword = i18n . t ( 'ReduxFormUtils.errorShortPassword' ) ;
4950 }
5051 return errors ;
5152}
5253
5354export function validateLogin ( formProps ) {
5455 const errors = { } ;
5556 if ( ! formProps . email ) {
56- errors . email = 'Please enter an email' ;
57+ errors . email = i18n . t ( 'ReduxFormUtils.errorEmptyEmail' ) ;
5758 }
5859 if ( ! formProps . password ) {
59- errors . password = 'Please enter a password' ;
60+ errors . password = i18n . t ( 'ReduxFormUtils.errorEmptyPassword' ) ;
6061 }
6162 return errors ;
6263}
@@ -67,29 +68,29 @@ export function validateSignup(formProps) {
6768 validateNameEmail ( formProps , errors ) ;
6869
6970 if ( ! formProps . password ) {
70- errors . password = 'Please enter a password' ;
71+ errors . password = i18n . t ( 'ReduxFormUtils.errorEmptyPassword' ) ;
7172 }
7273 if ( formProps . password && formProps . password . length < 6 ) {
73- errors . password = 'Password must be at least 6 characters' ;
74+ errors . password = i18n . t ( 'ReduxFormUtils.errorShortPassword' ) ;
7475 }
7576 if ( ! formProps . confirmPassword ) {
76- errors . confirmPassword = 'Please enter a password confirmation' ;
77+ errors . confirmPassword = i18n . t ( 'ReduxFormUtils.errorConfirmPassword' ) ;
7778 }
7879
7980 if ( formProps . password !== formProps . confirmPassword && formProps . confirmPassword ) {
80- errors . confirmPassword = 'Passwords must match' ;
81+ errors . confirmPassword = i18n . t ( 'ReduxFormUtils.errorPasswordMismatch' ) ;
8182 }
8283
8384 return errors ;
8485}
8586export function validateResetPassword ( formProps ) {
8687 const errors = { } ;
8788 if ( ! formProps . email ) {
88- errors . email = 'Please enter an email.' ;
89+ errors . email = i18n . t ( 'ReduxFormUtils.errorEmptyEmail' ) ;
8990 } else if (
9091 // eslint-disable-next-line max-len
9192 ! formProps . email . match ( EMAIL_REGEX ) ) {
92- errors . email = 'Please enter a valid email address.' ;
93+ errors . email = i18n . t ( 'ReduxFormUtils.errorInvalidEmail' ) ;
9394 }
9495 return errors ;
9596}
0 commit comments