Skip Navigation

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

Problem:
Custom Gutenberg block was being corrupted when switched to other language, as well as, the link wasn't being translated in block's scaffold (other than the HTML representation).

Solution:
Please see this guide https://wpml.org/documentation/support/language-configuration-files/make-custom-gutenberg-blocks-translatable/ and make sure that your block's scaffold is formed properly.

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.

This topic contains 12 replies, has 2 voices.

Last updated by Waqas Bin Hasan 1 year, 5 months ago.

Assisted by: Waqas Bin Hasan.

Author Posts
December 6, 2023 at 9:53 am #15005539

ansiteM

When duplicating content to a new language, it changes the link in the href but does not change the url in the custom gutenberg block(e.g. example.com/kontakt turns into example.com/en/contact). Unfortunately, this causes an error in the block (inconsistent data). Is it possible to force WPML to also change the url in a custom block or disable the automatic change in the href?

I tried adding in wpml-config but it doesn't work for duplication.

wpml-change2.png
wpml-change.png
December 7, 2023 at 10:47 am #15015809

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting the support.

By default WPML is set to auto-generate slugs from title but you can change this setting in WPML → Settings → Translated documents options.

In this case, it won't generate the slug automatically but you can then search for the slug in ATE while translating the post, and can translate it as needed (or can leave it as it is).

See following guides for details:

- https://wpml.org/documentation/getting-started-guide/translating-page-slugs/#sending-post-or-page-slugs-to-translators
- https://wpml.org/faq/how-to-translate-urls-shortcodes-and-html-attributes-using-the-advanced-translation-editor/#how-do-i-translate-urls-with-the-advanced-translation-editor

Alternatively, you can go to WPML -> Settings -> Translate Link Targets and click "Scan now and adjust links" to adjust links in posts and strings so they point to the translated content.

Remember to take full backup of site and database before proceeding with any of these.

Regards.

December 7, 2023 at 1:02 pm #15016909

ansiteM

The problem is not the slug translation(it is generated correctly).

The problem is with the content of posts and pages.

When I copy a page to another language, the links in the content are automatically replaced, but they are not changed in the gutenberg block attributes.

Changing "WPML → Settings → Translated documents options" does not change the way the link is replaced in the content

Using "WPML -> Settings -> Translate Link Targets" change url in

but

"buttonLink":"hidden link" didn't change to "buttonLink":"hidden link"

Zrzut ekranu 2023-12-07 140214.png
Zrzut ekranu 2023-12-07 140208.png
December 8, 2023 at 8:43 am #15023431

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for the details.

May I ask for the debug information of your website for an overview of your setup? See https://wpml.org/faq/provide-debug-information-faster-support/ for more information.

I've enabled the debug information section for your next reply.

Additionally you can also take a look at https://wpml.org/faq/checklist-before-opening-a-ticket-in-wpml-support/ and cross-check for a few initial fixes.

See https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/ for details on privacy and security.

December 8, 2023 at 10:42 am #15024691

ansiteM

I am sending debug information

December 8, 2023 at 12:29 pm #15025519

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for the debug information.

I need to take a closer look at your site. So I request temporary access (WP-Admin and FTP), preferably to a test site where the problem has been replicated.

Your next answer will be private, to share this information safely.

Also provide detailed steps to reproduce the issue and links to pages in admin and on frontend.

IMPORTANT: Please take a complete backup of the site to avoid data loss. I may need to activate/deactivate plugins also.

See https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/ for details on privacy and security.

Please note that I'll be able to return to you on Monday due to the weekend.

December 11, 2023 at 6:15 am #15033203

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for the access, I am working on it and 'll get back to you accordingly.

December 11, 2023 at 12:24 pm #15036823

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for your patience and cooperation.

I was able to observe the problem by trying different things. I observed that the problem isn't with WPML but coming from "GreenShift - Animation and Page Builder Blocks" plugin itself.

For example, this page hidden link, if you see that button's URL is pointing to correct English version of Kontakt page, while if you edit this page, you'll see the block is broken.

Proof of concept:
- Create a new page with that GreenShift ButtonBox block, in default (Polish) language.
- Set a URL to "Kontakt" page (i.e. hidden link).
- Publish the page.
- Click "duplicate" in Languages section and duplicate the page to English.
- Edit the English translation (duplicated in previous step).
--- (Optional) Click "Translate Independently" in Languages section.
- Make any change to the page, except the block which looks broken.
- Save the page.
- Check on frontend, that button has correct URL to English version of the Kontakt page (hidden link).
- However, if you attempt to recover the block, it recovers fine. But of course, you've to adjust the link by yourself.

In short, WPML does its work correctly. But it is the block which becomes corrupt. This is a compatibility problem and you may check with plugin author for a compatibility update. Because this plugin isn't on our compatibility list (https://wpml.org/plugin/?wpv_view_count=120064&wpv-plugin-functionality=0&wpv_post_search=GreenShift&wpv-wpcf-recommendation-flag=&wpv_filter_submit=Search).

Theme and plugin authors are welcome to join WPML’s Go Global program, which helps them make their code multilingual ready. Together with WPML’s compatibility team, they can test and confirm that their theme or plugin works with WPML. See https://wpml.org/documentation/support/go-global-program/ for details and you can refer your theme/plugin provider to this as well.

December 11, 2023 at 2:50 pm #15038725

ansiteM

Thanks for reply and efford.

Block becomes corruptet because WPML don't see key "buttonLink" in block and didn't translate it but WPML see link in

Zrzut ekranu 2023-12-11 154249.png
Zrzut ekranu 2023-12-11 153942.png
December 12, 2023 at 6:18 am #15042199

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Yes I understand your point.

Let me try a few more things and 'll get back to you accordingly.

December 12, 2023 at 10:53 am #15044467

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for your patience.

I tested again in your site and I am still convinced that problem is with custom block's scaffold. I followed this guide for examples https://wpml.org/documentation/support/language-configuration-files/make-custom-gutenberg-blocks-translatable/ and compared your block's scaffold also. Perhaps you need to check according to these lines.

Because I removed the XML from wpml-config.xml from plugin's folder and block is still corrupted when switched to other language (i.e. duplicating the post).

Another proof of concept is that, if you see the code of corrupted block, the A's href attribute contains translated link already - check this screencast: hidden link

While, in ATE, all the attributes look just fine. I tested this with your XML added to the config, as well as, without the XML (see attached).

For the links, which are by default not visible in ATE, you have to search for http or https to find these links for translation.

gb5.jpg
gb4.jpg
gb3.jpg
gb2.jpg
gb1.jpg
December 12, 2023 at 1:04 pm #15046163

ansiteM

Thank you for checking.

Does WPML have a hook that is triggered when translating links? Then I could add my own filtering.

December 12, 2023 at 1:32 pm #15046491

Waqas Bin Hasan
WPML Supporter since 05/2014

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

WPML offers filters and action hooks that can be used in your WordPress theme or plugin to provide correct multilingual support. Browse following resources for more information:

- https://wpml.org/documentation/support/wpml-coding-api/
- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/
- https://wpml.org/documentation/support/wpml-coding-api/shortcodes/
- https://wpml.org/faq/how-to-get-current-language-with-wpml/
- https://wpml.org/documentation/support/wpml-tables/
- https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/
- https://wpml.org/documentation/support/