
Tagged: shortcode, translations, wpml, WPML Config File
-
AuthorPosts
-
April 1, 2025 at 5:39 pm #1480589
I am using the WP Booking System plugin together with the Enfold theme. WP Booking System does not support WPML, but it allows me to create the booking form in 3 languages. I need to insert a slightly different shortcode in the editor (lang=en, lang=de etc.) per language.
[wpbs id="1" language="nl" title="no" legend="yes" legend_position="side" display="1" year="0" month="0" language="auto" start="1" dropdown="yes" jump="no" history="1" tooltip="1" highlighttoday="no" weeknumbers="no" show_first_available_date="no" form_id="1" form_position="bottom" auto_pending="yes" selection_type="multiple" selection_style="split" minimum_days="0" maximum_days="0" booking_start_day="0" booking_end_day="0" show_date_selection="no"]
So I create a WPML config file in the root folder of my Enfold child theme with the following content:
<wpml-config> <shortcodes> <shortcode> <tag>wpbs</tag> <attributes> <attribute>id</attribute> <attribute>language</attribute> </attributes> </shortcode> </shortcodes> </wpml-config>
I reopened the page, updated the content, but I can still not change the German and English page through the Advanced Translation editor.
Do you have any clue what I am doing wrong?PS. I have tried this solution with both a content block and a code block, both don’t give me any result.
April 2, 2025 at 6:05 am #1480613Hey envis,
Thank you for the inquiry.
Have you tried placing the shortcode inside a Text Block? You should be able to translate the content of the Text Block element in the WPML Translation Editor. If this doesn’t work, please provide the login details in the private field. For additional assistance, please contact the WP Booking System plugin developers.
Best regards,
IsmaelApril 2, 2025 at 5:38 pm #1480655Ismael,
I asked WPML and they came up with this solution.
So I expect that because of this XML, I would see an ID and LANGUAGE attribute that I can change with WPML per language version. But I do not.
Greetings,
Gerben-
This reply was modified 3 weeks, 3 days ago by
envis.
April 3, 2025 at 7:27 am #1480687Hi,
Thank you for the info.
We would like to try to override the wpml-config using the dedicated field in WPML > Settings (https://wpml.org/documentation/support/language-configuration-files/overriding-language-configuration-files/), but a script error prevents us from saving the changes. This is the error:
Uncaught SyntaxError: Unexpected token '<' (at https://site.de/?wpml-app=ate-dashboard&ver=472900:8:1) Line:8 ateDashboard(params); <pre style="padding:1em; background-color: #f8f8f8; color: #0a001f"><?xml version="1.0" encoding="UTF-8"?> <shortcodes> <shortcode> <tag>av_codeblock</tag> <attributes> <attribute>alb_description</attribute> <attribute>av_uid</attribute> <attribute>codeblock_type</attribute>
This might also be the reason why the Text Block and other elements are not translatable. Please forward this error to WPML support and once the issue is fixed, try to delete the wpml-config.xml file in the child theme folder, then transfer its content into the WPML > Settings > Custom XML Configuration tab.
Let us know the result.
Best regards,
IsmaelApril 3, 2025 at 9:16 am #1480704Maybe this was a human error. The wpml-config.xml was missing from the enfold theme folder. I have put it back there. Can you try again? Or does it have nothing to do with it?
April 3, 2025 at 9:32 am #1480707Hi,
We actually removed the code from the config file for testing. Please try to completely remove the config xml file, then paste its content into W.P.M.L > Settings > Custom XML Configuration. You may need to forward the error to W.P.M.L support first.
Best regards,
IsmaelApril 8, 2025 at 12:03 pm #1480994April 9, 2025 at 4:59 am #1481037Hi,
Yes, the builder elements should be translatable, but this doesn’t seem to be working due to the error mentioned above. Fixing the error should allow you to translate the content of the Text Block and place different versions of the wpbs shortcode for different languages.
Another option is to create a custom shortcode that wraps the wpbs shortcode and alters the id and language attribute based on the active WPML language. Please add this code in the functions.php file:
function av_wpbs_wpml_cb() { $lang = apply_filters('wpml_current_language', null); $id = 1; $language = 'en'; switch ($lang) { case 'nl': $id = 1; $language = 'nl'; break; case 'fr': $id = 2; $language = 'fr'; break; case 'de': $id = 3; $language = 'de'; break; default: $id = 1; $language = 'en'; break; } return do_shortcode('[wpbs id="' . esc_attr($id) . '" language="' . esc_attr($lang) . '" title="no" legend="yes" legend_position="side" display="1" year="0" month="0" start="1" dropdown="yes" jump="no" history="1" tooltip="1" highlighttoday="no" weeknumbers="no" show_first_available_date="no" form_id="1" form_position="bottom" auto_pending="yes" selection_type="multiple" selection_style="split" minimum_days="0" maximum_days="0" booking_start_day="0" booking_end_day="0" show_date_selection="no"]'); } add_shortcode('av_wpbs_wpml', 'av_wpbs_wpml_cb');
Instead of using the default shortcode, you can use this instead:
[av_wpbs_wpml]
Best regards,
IsmaelApril 9, 2025 at 4:41 pm #1481088Ismael,
Thank you very much for your solution. I have added your shortcode generator in functions.php of the child-theme.
function av_wpbs_wpml_cb() { $lang = apply_filters('wpml_current_language', null); $id = 1; $language = 'en'; switch ($lang) { case 'nl': $id = 1; $language = 'nl'; break; case 'en': $id = 1; $language = 'en'; break; case 'fr': $id = 1; $language = 'de'; break; default: $id = 1; $language = 'nl'; break; } return do_shortcode('[wpbs id="' . esc_attr($id) . '" language="' . esc_attr($lang) . '" show_prices="yes" title="no" legend="yes" legend_position="side" display="1" year="0" month="0" start="1" dropdown="yes" jump="no" history="1" tooltip="1" highlighttoday="no" weeknumbers="no" show_first_available_date="no" form_id="1" form_position="bottom" auto_pending="yes" selection_type="multiple" selection_style="split" minimum_days="7" maximum_days="0" booking_start_day="6" booking_end_day="6" show_date_selection="no"]'); } add_shortcode('av_wpbs_wpml', 'av_wpbs_wpml_cb');
Then added the shortcode to a text block:
[av_wpbs_wpml]
Test URL:
https://villasari.de/nl/test-shortcode/I get this error:
Fatal error: Uncaught TypeError: ksort(): Argument #1 ($array) must be of type array, null given in /var/www/vhosts/villasari.de/httpdocs/wp-content/plugins/multilingual-tools-2.2.6/inc/class-mltools-shortcode-attribute-filter.php:86 Stack trace: #0 /var/www/vhosts/villasari.de/httpdocs/wp-content/plugins/multilingual-tools-2.2.6/inc/class-mltools-shortcode-attribute-filter.php(86): ksort() #1 /var/www/vhosts/villasari.de/httpdocs/wp-content/plugins/multilingual-tools-2.2.6/inc/class-mltools-shortcode-attribute-filter.php(66): MLTools_Shortcode_Attribute_Filter->add_tag() #2 /var/www/vhosts/villasari.de/httpdocs/wp-includes/class-wp-hook.php(326): MLTools_Shortcode_Attribute_Filter->do_shortcode_tag_filter() #3 /var/www/vhosts/villasari.de/httpdocs/wp-includes/plugin.php(205): WP_Hook->apply_filters() #4 /var/www/vhosts/villasari.de/httpdocs/wp-includes/shortcodes.php(447): apply_filters() #5 [internal function]: do_shortcode_tag() #6 /var/www/vhosts/villasari.de/httpdocs/wp-includes/shortcodes.php(273): preg_replace_callback() #7 /var/www/vhosts/villasari.de/httpdocs/wp-content/themes/enfold/config-templatebuilder/avia-template-builder/php/class-shortcode-helper.php(580): do_shortcode() #8 /var/www/vhosts/villasari.de/httpdocs/wp-content/themes/enfold/config-templatebuilder/avia-shortcodes/textblock/textblock.php(541): ShortcodeHelper::avia_apply_autop() #9 /var/www/vhosts/villasari.de/httpdocs/wp-content/themes/enfold/config-templatebuilder/avia-template-builder/php/class-shortcode-template.php(1329): avia_sc_text->shortcode_handler() #10 /var/www/vhosts/villasari.de/httpdocs/wp-includes/shortcodes.php(434): aviaShortcodeTemplate->shortcode_handler_prepare() #11 [internal function]: do_shortcode_tag() #12 /var/www/vhosts/villasari.de/httpdocs/wp-includes/shortcodes.php(273): preg_replace_callback() #13 /var/www/vhosts/villasari.de/httpdocs/wp-includes/class-wp-hook.php(324): do_shortcode() #14 /var/www/vhosts/villasari.de/httpdocs/wp-includes/plugin.php(205): WP_Hook->apply_filters() #15 /var/www/vhosts/villasari.de/httpdocs/wp-content/themes/enfold/template-builder.php(102): apply_filters() #16 /var/www/vhosts/villasari.de/httpdocs/wp-includes/template-loader.php(106): include('...') #17 /var/www/vhosts/villasari.de/httpdocs/wp-blog-header.php(19): require_once('...') #18 /var/www/vhosts/villasari.de/httpdocs/index.php(17): require('...') #19 {main} thrown in /var/www/vhosts/villasari.de/httpdocs/wp-content/plugins/multilingual-tools-2.2.6/inc/class-mltools-shortcode-attribute-filter.php on line 86
Any clue?
April 10, 2025 at 6:18 am #1481118Hi,
Thank you for the update.
The error doesn’t occur when the Multilingual Tools plugin is disabled. And according to the following documentation, the booking form fields need to be translated manually using the translation option in the backend — WPML will not translate the fields automatically.
— https://www.wpbookingsystem.com/documentation/translations/
To test this, we translated the first field Familienaam to Family Name.
Result:
Best regards,
IsmaelApril 10, 2025 at 8:45 pm #1481152Ismael,
You are awesome, thanx for that :) It works like a charm.
I have translated the form in the WP Booking System plugin and it looks good.But it seems like a side effect showed up. I have a button on the same page in the bottom. But that button URL is not translateable anymore in WPML. It used to be. Can this be related to your fix?
-
This reply was modified 2 weeks, 1 day ago by
envis.
April 11, 2025 at 5:37 am #1481176Hi,
Glad to know it’s working correctly now. As for the button, it seems to be translated correctly on our end.
Best regards,
Ismael -
This reply was modified 3 weeks, 3 days ago by
-
AuthorPosts
- You must be logged in to reply to this topic.