Quform now has an integration with WPML, see our WPML integration guide for how to get started.

Show legacy instructions

With the form created in English use the code below to translate the field labels and button text to German when viewing a German page. Add the code below to the WordPress theme functions.php file (or create a plugin for it).

123456789
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
add_action('quform_pre_display_1', function (Quform_Form $form) {    if (defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE == 'de') {        my_set_element_config($form, '1_3', 'label', 'Name');        my_set_name_element_part_config($form, '1_3', 2, 'subLabel', 'Vorname');        my_set_name_element_part_config($form, '1_3', 4, 'subLabel', 'Nachname');        my_set_element_config($form, '1_4', 'label', 'E-Mail');        my_set_element_config($form, '1_5', 'label', 'Ihre Nachricht');        $form->setConfig('submitText', 'Senden');    }
});
 
function my_set_element_config($form, $elementUniqueId, $key, $value)
{
    $element = $form->getElement("quform_$elementUniqueId");
 
    if ($element) {
        $element->setConfig($key, $value);
    }
}
 
function my_set_name_element_part_config($form, $elementUniqueId, $partKey, $key, $value)
{
    $element = $form->getElement("quform_$elementUniqueId");
 
    if ($element instanceof Quform_Element_Name) {
        $part = $element->getPart($partKey);
 
        if ($part) {
            $part->setConfig($key, $value);
        }
    }
}
add_action('quform_pre_display_1', function (Quform_Form $form) {
    if (defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE == 'de') {
        my_set_element_config($form, '1_3', 'label', 'Name');
        my_set_name_element_part_config($form, '1_3', 2, 'subLabel', 'Vorname');
        my_set_name_element_part_config($form, '1_3', 4, 'subLabel', 'Nachname');
        my_set_element_config($form, '1_4', 'label', 'E-Mail');
        my_set_element_config($form, '1_5', 'label', 'Ihre Nachricht');
        $form->setConfig('submitText', 'Senden');
    }
});

function my_set_element_config($form, $elementUniqueId, $key, $value)
{
    $element = $form->getElement("quform_$elementUniqueId");

    if ($element) {
        $element->setConfig($key, $value);
    }
}

function my_set_name_element_part_config($form, $elementUniqueId, $partKey, $key, $value)
{
    $element = $form->getElement("quform_$elementUniqueId");

    if ($element instanceof Quform_Element_Name) {
        $part = $element->getPart($partKey);

        if ($part) {
            $part->setConfig($key, $value);
        }
    }
}
  • On line 1, replace the number 1 with the form ID
  • On line 2, replace the de with the WPML language code
  • On lines 3-5, replace the 1_3 with the Name element unique ID, and change the translations as needed (remove these lines if the form does not have a Name type element)
  • On lines 6-7, replace the 1_4 and 1_5 with unique ID of any other element that you want to change the label of and set the label text to suit, these lines can be duplicated to translate additional field labels
  • On line 8, replace the textSenden with the desired submit button text
1
2
345678910
11
1213
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function my_form_translation(Quform_Form $form)
{
    if (defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE == 'de') {        my_set_element_config($form, '1_3', 'label', 'Name');        my_set_name_element_part_config($form, '1_3', 2, 'subLabel', 'Vorname');        my_set_name_element_part_config($form, '1_3', 4, 'subLabel', 'Nachname');        my_set_element_config($form, '1_4', 'label', 'E-Mail');        my_set_element_config($form, '1_5', 'label', 'Ihre Nachricht');        $form->setConfig('submitText', 'Senden');    }
}
add_action('quform_pre_display_1', 'my_form_translation'); 
function my_set_element_config($form, $elementUniqueId, $key, $value)
{
    $element = $form->getElement("quform_$elementUniqueId");
 
    if ($element) {
        $element->setConfig($key, $value);
    }
}
 
function my_set_name_element_part_config($form, $elementUniqueId, $partKey, $key, $value)
{
    $element = $form->getElement("quform_$elementUniqueId");
 
    if ($element instanceof Quform_Element_Name) {
        $part = $element->getPart($partKey);
 
        if ($part) {
            $part->setConfig($key, $value);
        }
    }
}
function my_form_translation(Quform_Form $form)
{
    if (defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE == 'de') {
        my_set_element_config($form, '1_3', 'label', 'Name');
        my_set_name_element_part_config($form, '1_3', 2, 'subLabel', 'Vorname');
        my_set_name_element_part_config($form, '1_3', 4, 'subLabel', 'Nachname');
        my_set_element_config($form, '1_4', 'label', 'E-Mail');
        my_set_element_config($form, '1_5', 'label', 'Ihre Nachricht');
        $form->setConfig('submitText', 'Senden');
    }
}
add_action('quform_pre_display_1', 'my_form_translation');

function my_set_element_config($form, $elementUniqueId, $key, $value)
{
    $element = $form->getElement("quform_$elementUniqueId");

    if ($element) {
        $element->setConfig($key, $value);
    }
}

function my_set_name_element_part_config($form, $elementUniqueId, $partKey, $key, $value)
{
    $element = $form->getElement("quform_$elementUniqueId");

    if ($element instanceof Quform_Element_Name) {
        $part = $element->getPart($partKey);

        if ($part) {
            $part->setConfig($key, $value);
        }
    }
}
  • On line 3, replace the de with the WPML language code
  • On lines 4-6, replace the 1_3 with the Name element unique ID, and change the translations as needed (remove these lines if the form does not have a Name type element)
  • On lines 7-8, replace the 1_4 and 1_5 with unique ID of any other element that you want to change the label of and set the label text to suit, these lines can be duplicated to translate additional field labels
  • On line 9, replace the textSenden with the desired submit button text
  • On line 12, replace the number 1 with the form ID
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy