Scenario: You have a website in English and would like to offer one form in Spanish. Gravity Forms does not offer this feature so here’s how you do it.
Manually change the Form Fields titles to Spanish. If you are using placeholders you can manually change those as well.
Manually change the “Custom Validation Message” for each field:
Change the form confirmation messages to Spanish and any customer notifications emails as well.
This is the coding requirement part, the gravity form error messages will still be in English so add the following code to your functions.php file or my preference is to use the Code Snippets plugin to add the code:
This code will change the page you embed your Spanish form on to be identified as being in Spanish instead of your websites default language (English):
add_filter('locale', function($locale) {
$path = trim($_SERVER['REQUEST_URI'], "/");
// get last part as slug
$arr = explode("/", $path);
$slug = end($arr);
if($slug === 'CHANGE-THIS-TO-YOUR-TARGET-PAGE-SLUG')
return 'es_AR';
return $locale; });
Here is the same code as above but for Hebrew Language:
add_filter('locale', function($locale) {
$path = trim($_SERVER['REQUEST_URI'], "/");
// get last part as slug
$arr = explode("/", $path);
$slug = end($arr);
if($slug === 'CHANGE-THIS-TO-YOUR-TARGET-PAGE-SLUG')
return 'he_IL';
return $locale;
});
This code manually changes specific error messages mostly for coupon code fields that are not able to be changed on the form itself and that are not changed by the default page language to Spanish. You can edit the code to reflect your desired language:
add_filter( 'gform_validation_message_8', 'change_message', 10, 2 );
function change_message( $message, $form ) {
return "<div class='validation_error'>Ha ocurrido un problema con tu solicitud. A continuación se han resaltado los errores." . '</div>';
}
add_filter( 'gform_field_content_8', function ( $field_content, $field ) {
if ( $field->id == 6 ) {
return str_replace( 'Apply', "Solicitar", $field_content );
}
return $field_content;
}, 10, 2 );
add_filter( 'gform_field_content_8', function ( $field_content, $field ) {
if ( $field->id == 6 ) {
return str_replace( 'SolicitarCouponCode', "ApplyCouponCode", $field_content );
}
return $field_content;
}, 10, 2 );
add_filter( 'gform_field_content_8', function ( $field_content, $field ) {
if ( $field->id == 6 ) {
return str_replace( 'DisableSolicitarButton', "DisableApplyButton", $field_content );
}
return $field_content;
}, 10, 2 );
Here is the same code but for Hebrew Language:
/*add_filter( 'gform_validation_message_10', 'change_message', 10, 2 );
function change_message( $message, $form ) {
return "<div class='validation_error'>.אירעה בעיה בבקשתך. השגיאות הודגשו בהמשך" . '</div>';
}*/
add_filter( 'gform_field_content_10', function ( $field_content, $field ) {
if ( $field->id == 6 ) {
return str_replace( 'Apply', "שלח", $field_content );
}
return $field_content;
}, 10, 2 );
add_filter( 'gform_field_content_10', function ( $field_content, $field ) {
if ( $field->id == 6 ) {
return str_replace( 'שלחCouponCode', "ApplyCouponCode", $field_content );
}
return $field_content;
}, 10, 2 );
add_filter( 'gform_field_content_10', function ( $field_content, $field ) {
if ( $field->id == 6 ) {
return str_replace( 'DisableשלחButton', "DisableApplyButton", $field_content );
}
return $field_content;
}, 10, 2 );