rimba
September 18, 2023, 7:57am
1
Hi,
I added a checkbox to the booking form by adding this code:
add_filter(
'hivepress/v1/forms/booking_make',
function( $form ) {
$form['fields']['Lei_requisitos'] = [
'required' => true,
'caption' => 'I have read the Requirements to carry out this procedure and I have everything necessary.',
'type' => 'checkbox',
'_order' => 123,
];
return $form;
},
1000
);
I works good but now I want to be able to translate it, what code do I have to add to the “caption” so it can be translated?
andrii
September 19, 2023, 10:22am
4
Hi,
The easiest option is to change the translation in this code, other options will require custom implementation.
rimba
September 19, 2023, 11:16am
5
This is when you are having a multilanguage site, I tried this and I worked, I dont know if this will be deleted when the plugin is updated… would be nice if the string part can be added in the snippet…
1.- On the snippet change this:
'caption' => 'I have read the Requirements to carry out this procedure and I have everything necessary.',
'type' => 'checkbox',
to:
'caption' => hivepress()->translator->get_string( 'lei_requisitos_caption' ),
2.- Add the string to the strings file (i this case in the booking plugin):
location: /plugins/hivepress-bookings/includes/config/strings.php
'lei_requisitos_caption' => esc_html__( 'lei_requisitos_caption', 'hivepress' ),
Now you only have to sync your language file in loco translate and the new text will apear in the list and its ready to be translated.
IF the caption will be one that hivepress or a plugin is already using (for example: name, phone, etc) it is easier:
replace the caption part on the snippet with:
‘label’ => esc_html__( ‘Phone’, ‘hivepress’ ),
in this case “Phone” its already translated by hivepress.