Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is trying to translate a form from English to Spanish using WPML, specifically needing to make the form shortcode translatable and handle numeric values like IDs in translations.
Solution:
First, we recommend adding the following XML configuration in WPML > Settings > Custom XML Configuration to make the shortcode translatable:

<wpml-config>
  <shortcodes>
    <shortcode>
      <tag>forminator_form</tag>
        <attributes>
          <attribute>id</attribute>
        </attributes><attributes>
    </attributes></shortcode>
  </shortcodes>
</wpml-config>

Next, use this PHP snippet to allow translating numeric values like IDs with the Advanced Translation Editor (ATE):

/**
 * Allow translating numbers
 *
 * @see https://wpml.org/forums/topic/wpbakery-post-grid-element-exclude-from-filter-list-category-reappears<br /> 
*/
function wpmlsupp_7499_allow_translating_numbers( $is_translatable, $job_translate ) {
    $data = $job_translate['field_data'];
if ( 'base64' === $job_translate['field_format'] ) {
$data = base64_decode( $data );
}
    if ( is_numeric( $data ) ) {
    return true;
    }
    return $is_translatable;
}
add_filter( 'wpml_tm_job_field_is_translatable', 'wpmlsupp_7499_allow_translating_numbers', 10, 2 );

After applying these changes, edit the form shortcode in the original content and open ATE. If the ID is not directly visible, use the search bar to locate it. When translating, replace the original ID with the correct ID of the translated form.

Please note that this solution might be outdated or not applicable to your specific case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket at WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Andreas W. 8 months, 3 weeks ago.

Assisted by: Andreas W..

Author Posts
September 17, 2024 at 4:51 pm #16189991

paulS-91

Background of the issue:
I am trying to translate a form from English to Spanish using WPML on my site hidden link. Specifically, I am translating [forminator_form id="5022"] (ENG form) to [forminator_form id="16786"] (SPA form).

Symptoms:
The translation works for a moment but then reverts back to the original English form [forminator_form id="5022"].

Questions:
Why does the translated form revert back to the original English form?
How can I ensure the translation remains stable and does not revert?

September 17, 2024 at 9:10 pm #16190708

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

It looks like this shortcode is coming from WP Bakery and you can not translate it directly on WPML String Translation, as the translations are coming from a page that is translated with the WPML Translation Editor.

The WPML Translation Editor (here Advanced Translation Editor) does not yet allow to translate such shortcodes.

We do have a workaround for this purpose, which would allow you to translate the ID of the form with the translation editor, but you would need a Child Theme to be able to implement it.

Would it be possible for you to implement a Child Theme for The7 Theme on your site?

Alternative:
Translate the page with the WordPress Editor.

Guide:
https://wpml.org/documentation/translating-your-contents/using-different-translation-editors-for-different-pages/

Best regards
Andreas

September 19, 2024 at 12:59 pm #16198890

paulS-91

Hello Andreas, thanks for your reply.

We currently use a custom plugin instead of a child theme to add such functionality to our website. We are happy to update this plugin with the code WPML provides if that is also suitable.

May I ask you for:
a) the code that needs to be included in the child theme, Or
b) if you think it will work (or recommend), the code that can be added to a custom plugin

Kind regards,
Juan

September 20, 2024 at 12:48 am #16201002

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello Juan,

Please give it a try.

First, at WPML > Settings > Custom XML Configuration (tab) enter this XML markup to make the shortcode translatable:

<wpml-config>
  <shortcodes>
    <shortcode>
      <tag>forminator_form</tag>
        <attributes>
          <attribute>id</attribute>
        </attributes>
    </shortcode>
  </shortcodes>
</wpml-config>

Next, use this snippet to make numeric values (id) translatable with the Advanced Translation Editor (ATE).

/**
 * Allow translating numbers
 *
 * @see https://wpml.org/forums/topic/wpbakery-post-grid-element-exclude-from-filter-list-category-reappears
 */
function wpmlsupp_7499_allow_translating_numbers( $is_translatable, $job_translate ) {
    $data = $job_translate['field_data'];
	if ( 'base64' === $job_translate['field_format'] ) {
		$data = base64_decode( $data );
	}
    if ( is_numeric( $data ) ) {
    	return true;
    }
    return $is_translatable;
}
add_filter( 'wpml_tm_job_field_is_translatable', 'wpmlsupp_7499_allow_translating_numbers', 10, 2 );

Now, edit the form shortcode on the original content and open ATE. If you can not directly see the ID please try to search for it inside the search bar on top.

Now, when translating your content, translate the ID and replace it with the correct ID of the translated form. (each form has its proper ID)

I hope this will solve the issue for you. Take note, that this will not be solvable with automatic translation. You will need to adapt the IDs manually inside ATE.

Best regards
Andreas