55
66import { useVGSCollectFormInstance } from '@vgs/collect-js-react' ;
77import { useCallback } from '@wordpress/element' ;
8+ import { __ } from '@wordpress/i18n' ;
89import type { VGS } from '@vgs/collect-js' ;
910
1011/**
@@ -53,28 +54,28 @@ export function getVgsFormValidationError( formData: VGS.FormData ): string | nu
5354 if ( fieldName === 'card_number' || fieldName === 'card-number' ) {
5455 switch ( errorCode ) {
5556 case 1001 :
56- return 'Card number is required.' ;
57+ return __ ( 'Card number is required.' , 'calypso' ) ;
5758 case 1011 :
58- return 'Card number is invalid.' ;
59+ return __ ( 'Card number is invalid.' , 'calypso' ) ;
5960 }
6061 } else if ( fieldName === 'card_exp' || fieldName === 'card-expiration-date' ) {
6162 switch ( errorCode ) {
6263 case 1001 :
63- return 'Expiration date is required.' ;
64+ return __ ( 'Expiration date is required.' , 'calypso' ) ;
6465 case 1015 :
65- return 'Expiration date is invalid.' ;
66+ return __ ( 'Expiration date is invalid.' , 'calypso' ) ;
6667 }
6768 } else if ( fieldName === 'card_cvc' || fieldName === 'card-security-code' ) {
6869 switch ( errorCode ) {
6970 case 1001 :
70- return 'Security code is required.' ;
71+ return __ ( 'Security code is required.' , 'calypso' ) ;
7172 case 1017 :
72- return 'Security code is invalid.' ;
73+ return __ ( 'Security code is invalid.' , 'calypso' ) ;
7374 }
7475 }
7576
7677 // Default error message
77- return error . message || 'Please check your card details.' ;
78+ return error . message || __ ( 'Please check your card details.' , 'calypso' ) ;
7879}
7980
8081/**
@@ -91,15 +92,18 @@ export function useVgsFormValidation() {
9192 if ( ! form ) {
9293 return {
9394 isValid : false ,
94- errorMessage : 'Payment form is not ready. Please wait for the form to load.' ,
95+ errorMessage : __ (
96+ 'Payment form is not ready. Please wait for the form to load.' ,
97+ 'calypso'
98+ ) ,
9599 } ;
96100 }
97101
98102 const formData = form . state ;
99103 if ( ! formData ) {
100104 return {
101105 isValid : false ,
102- errorMessage : 'Please enter your card details.' ,
106+ errorMessage : __ ( 'Please enter your card details.' , 'calypso' ) ,
103107 } ;
104108 }
105109
0 commit comments