Skip Navigation

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

Problem:
The client needed a solution for internal links in translations pointing to the default language after translating blog posts.

Solution:
We recommended manually translating the internal links in BeBuilder widgets as a temporary workaround. This solution is detailed in our errata, which you can find here: https://wpml.org/errata/betheme-internal-links-in-translations-point-to-default-language/.

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 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.

This topic contains 21 replies, has 2 voices.

Last updated by Waqas Bin Hasan 1 month ago.

Assisted by: Waqas Bin Hasan.

Author Posts
September 24, 2024 at 7:37 am #16212730

Waqas Bin Hasan
Supporter

Languages: English (English )

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

Thank you for your patience and cooperation.

Our team has published an errata at https://wpml.org/errata/betheme-internal-links-in-translations-point-to-default-language/, I'll recommend subscribing to the comments of this errata, so you can get an update whenever there's more to it.

Unfortunately so far, the only workaround is to manually translate internal links in BeBuilder widgets.

September 24, 2024 at 9:09 pm #16217631

martinM-117

What does this errata means?
It seems like place for cold cases to let it be there :/
Does it mean, it will not be fixed at all ?

September 25, 2024 at 8:19 am #16218891

Waqas Bin Hasan
Supporter

Languages: English (English )

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

A published errata means that the case is in development and we'll be publishing any relevant updates on the said errata page.

You can find several errata pages at https://wpml.org/errata/ with different statues like Open, Resolved, Waiting for author and etc. So these're not cold cases, however, may take some time to fix and improve (due to current load of work).

This errata offers temporary solution, which is using manual translation for now. Once you fix the URL by manually translating it, the translation memory 'll help in future translations of the same URL. So practically you'll not need to translate again the same URL.

Unfortunately that's the only way of doing it so far.

September 26, 2024 at 9:27 am #16223970

Waqas Bin Hasan
Supporter

Languages: English (English )

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

Thank you for your patience and cooperation.

Our team suggested the following workaround, which I've tried in your test site and this seem to fix the links problem.

- Take a backup of the site before proceeding.
- Open the app/public/wp-content/themes/betheme/functions/builder/class-mfn-builder-front.php file
- Look for the folloiwng code, around line 2645:

public function show_items($item, $i, $vb, $w_iterate = false){

  		/*echo '<pre>';
  		print_r($item);
  		echo '</pre>';*/

  		$inner_class = array();
  		$item_class = array();

- And replace with:


public function show_items($item, $i, $vb, $w_iterate = false){
	/*echo '<pre>';
	print_r($item);
	echo '</pre>';*/

	// WPML Workaround for compsupp-7547
	if ( class_exists('Sitepress') && isset($item['attr']['content']) && is_string($item['attr']['content']) ) {

		// Find the links in the content
		$pattern = '/<a\s[^>]*href=["\']([^"\']+)["\']/i';

		// Replace with translated URLs
		$item['attr']['content'] = preg_replace_callback($pattern, function($matches) {
			
			$original_url = $matches[1];

			$wpml_current_lang = apply_filters( 'wpml_current_language', NULL );
			$translated_url = apply_filters('wpml_permalink', $original_url, $wpml_current_lang, true);

			return str_replace($original_url, $translated_url, $matches[0]);
		}, $item['attr']['content']);
	}

	$inner_class = array();
	$item_class = array();

This should be enough to display the translated URLs in the front-end.

Please note that this is more a workaround and not a proper fix, so keep an eye out for any problems that may arise.

October 1, 2024 at 7:31 pm #16242640

martinM-117

Hello,
Thank you for your effort, but Im not much confident into changing php codes, which I then need to replace every time, when BeTheme comes with update.
If I understand corectly, this piece of code bypass automatic link targeting and changes urls in translated pages directly in front end? This looks, like it can bring many problems into the site as whole. I would rather vote for a proper solution.

Thanks
Martin

October 1, 2024 at 7:55 pm #16242666

martinM-117

You said, that you aplied the code in the test site yes?

I tried to test it on this article:
hidden link

and both internal links to Sidari Beach and Apotripipi Beach links back into the canal D amour article.

So it doesnt look like working

October 2, 2024 at 7:14 am #16243486

Waqas Bin Hasan
Supporter

Languages: English (English )

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

Thank you for the updates.

That solution is temporary and you're right, until there's a proper solution, you'll need to keep track of this change after a theme update.

Our team is still working on this.

However, if you don't want to use that code, our team has published an errata recently at https://wpml.org/errata/betheme-internal-links-in-translations-point-to-default-language/. As per the errata:

Currently, the only workaround is to manually translate internal links in BeBuilder widgets.

So I'll request to try translating links manually then.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.