[Resolved] Translate Elementor Dynamic tag custom field
This thread is resolved. Here is a description of the problem and solution.
Problem: The client is developing a site using Elementor and has created a custom dynamic tag. They are able to translate default tag fields but are unsure how to translate custom fields added to their dynamic tag.
Solution: We recommend the following steps to enable translation for custom fields in Elementor dynamic tags: 1. Ensure that the custom fields are properly configured in the WPML settings. You can refer to our documentation on how to translate custom Elementor widgets: https://wpml.org/documentation/plugins-compatibility/elementor/how-to-add-wpml-support-to-custom-elementor-widgets/ 2. Register the custom fields for translation using the WPML String Translation interface. This involves wrapping the custom field values in gettext calls and registering them. Here is an example of how you can register a custom field:
public function render(): void {<br /> // Grab settings<br /> $text = (string) $this->get_settings( 'text_param' );<br /> $number = (int) $this->get_settings( 'number_param' );<br /> $select = (string) $this->get_settings( 'select_param' );<br /><br /> // --- WPML translation for the text field ---<br /> // Use a stable domain and a reasonably unique name to avoid collisions across pages.<br /> $domain = 'elementor-random-number-dynamic-tag';<br /> $post_id = function_exists('get_the_ID') ? (int) get_the_ID() : 0;<br /> $name = sprintf( 'text_param|post:%d', $post_id );<br /><br /> // 1) Register the original string (safe to leave in place permanently)<br /> do_action( 'wpml_register_single_string', $domain, $name, $text );<br /><br /> // 2) Fetch the translated version (if any)<br /> $text_translated = apply_filters( 'wpml_translate_single_string', $text, $domain, $name );<br /><br /> // ---- your actual output ----<br /> // (Example: echo the translated text, the random number, etc.)<br /> echo esc_html( $text_translated );<br />}
If this solution does not resolve your issue or seems outdated, 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 problem persists, please open a new support ticket at our 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.
Background of the issue:
I am developing a site and have created a custom Elementor dynamic tag using the documentation at hidden link. I added custom controls to this tag as per hidden link. I am trying to translate these custom fields.
Symptoms:
I can translate default tag fields like before, after, fallback, video_url, and shortcode, but I don't know how to translate my custom fields.
Questions:
How can I translate custom fields in Elementor dynamic tags?
Welcome to the WPML support forum. Before passing this thread to my colleague, I would like to share some suggestions and possible solutions for the issues you mentioned.
In short, WPML doesn’t automatically “know” about the extra controls you added to your custom Elementor Dynamic Tag which is what we have to configure first before they can be translated.
Please review the following documentation on how to translate custom elements with WPML.
I would like to request temporary access (wp-admin and FTP) to your site to test the issue.
(preferably to a test site where the problem has been replicated if possible)
**Before we proceed It is necessary to take FULL BACKUP of your database and your website. Providing us with access, you agree that a backup has been taken **
I often use the Duplicator plugin for this purpose: http://wordpress.org/plugins/duplicator/
You will find the needed fields for this below the comment area when you log in to leave your next reply.
The information you enter is private which means only you and I have access to it.
NOTE: If access to the live site is not possible and the staging site does not exist please provide me with a duplicator package created with the duplicator plugin.
We don’t explicitly mention dynamic tags in our documentation, but you should be able to translate them. In fact, we have an errata that addresses a similar issue.
That said, this isn’t a common request and at the moment I have not found another recently reported case.
Without access to either your staging or live environment, the guidance I can provide may not fully reflect your specific setup especially since you are using a custom dynamic tag.
If you’d like, we can create a sandbox environment and attempt to reproduce the issue. Here’s a sandbox I’ve already set up for us: hidden link
Each time, I don't understand why you can't test on your staging environnement. You have just to create a dynamic tag with custom controls. Just copy the example in documentation and you can see that it doesn't work. Okay, if in this case it works for you, I will share temporary access.
Anyway, of course without ftp access I crashed your sandbox.
I can too share access to my sandbox where I reproduced the issue.
please go to WPML->string translation and let me know if the fields showing now are the desired fields.
to verify the fields wraped in a gettext call are showing ok
the content of the text-param value is not translatable, however i am not sure you wanted that specific parameter to be translatable.
Also note the title picked up for translation now under the domain elementor-random-number-dynamic-tag
I was able to register it using
public function render(): void {
// Grab settings
$text = (string) $this->get_settings( 'text_param' );
$number = (int) $this->get_settings( 'number_param' );
$select = (string) $this->get_settings( 'select_param' );
// --- WPML translation for the text field ---
// Use a stable domain and a reasonably unique name to avoid collisions across pages.
$domain = 'elementor-random-number-dynamic-tag';
$post_id = function_exists('get_the_ID') ? (int) get_the_ID() : 0;
$name = sprintf( 'text_param|post:%d', $post_id );
// 1) Register the original string (safe to leave in place permanently)
do_action( 'wpml_register_single_string', $domain, $name, $text );
// 2) Fetch the translated version (if any)
$text_translated = apply_filters( 'wpml_translate_single_string', $text, $domain, $name );
// ---- your actual output ----
// (Example: echo the translated text, the random number, etc.)
echo esc_html( $text_translated );
// If you still want the random number, keep your original:
// echo rand();
}
That's very kind, really but of course I know i can use these function to translate my field.
My question was to translate custom dynamic tag controls like custom widget controls. (Included in the translation of the page and without the need of manually calls of a translate function).