Skip Navigation

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

Problem: After WPML update, the page builder strings are all missing from WPML > String Translation and can't be translated.

Solution: You can add this snippet directly in the functions.php file of your theme.

/**
 * Fix corrupted page builder package strings (wrong name and/or duplicates).
 *
 * @see https://onthegosystems.myjetbrains.com/youtrack/issue/wpmlcore-6913
 */
function wpmlcore_6913_fix_corrupted_package_strings() {
	global $wpdb;

	// Will collect all package string with a wrong name.
	$allCorrupted = wpml_collect( $wpdb->get_results(
		"SELECT
			s1.id,
			s1.string_package_id,
			s1.value,
			s1.name,
			s2.id AS duplicate_of_valid_id
		FROM {$wpdb->prefix}icl_strings AS s1
		LEFT JOIN {$wpdb->prefix}icl_strings AS s2 ON s2.name = MD5(s1.value)
		WHERE s1.string_package_id IS NOT NULL
			AND s1.name <> MD5(s1.value)
		ORDER BY s1.id"
	) )->keyBy( 'id' );

	if ( ! $allCorrupted->count() ) {
		return;
	}

	// duplicated string of a valid one => to delete
	$duplicatesOfNonCorrupted = $allCorrupted->filter( function( $string ) { return (bool) $string->duplicate_of_valid_id; } );
	// duplicated string with no valid one => keep the latest version and remove the other duplicates
	$corruptedDuplicates = $allCorrupted->diffKeys( $duplicatesOfNonCorrupted );

	// We'll keep the highest string id only
	$duplicatesToKeepAsUnique = $corruptedDuplicates
		->reduce( function( \WPML\Collect\Support\Collection $carry, $string ) {
			// Duplicated value/package_id will be overwritten.
			$key = md5( $string->string_package_id . $string->value );
			$carry->put( $key, $string );

			return $carry;
		}, wpml_collect() )
		->keyBy( 'id' );

	$duplicatesToDelete = $corruptedDuplicates->diffKeys( $duplicatesToKeepAsUnique );
	$stringIdsToDelete  = $duplicatesOfNonCorrupted->merge( $duplicatesToDelete )->pluck( 'id' )->toArray();

	if ( $stringIdsToDelete ) {
		wpml_unregister_string_multi( $stringIdsToDelete );
	}

	if ( $duplicatesToKeepAsUnique->count() ) {
		$wpdb->query(
			"UPDATE {$wpdb->prefix}icl_strings
		SET
			name = MD5(value),
			domain_name_context_md5 = MD5(CONCAT(context,MD5(value),gettext_context))
		WHERE id IN(" . $duplicatesToKeepAsUnique->implode( 'id', ',' ) . ")"
		);
	}
}
add_action( 'admin_footer', 'wpmlcore_6913_fix_corrupted_package_strings' );

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 18 replies, has 5 voices.

Last updated by Alejandro 8 months, 3 weeks ago.

Assigned support staff: Alejandro.

Author Posts
October 25, 2019 at 9:36 am

noamK-2

Hello,

1. Our website's main Language is English. Secondary is Hebrew - a right-to-left language.

2. We use Classic Translation Editor for translating all our content, except when it is required to use string translation.

3. WordPress version, theme version and all plugins are all up-to-date. Our theme - Consulting Theme by StylemixThemes, is on your list of compatible themes.

4. Our Issue:

After recent WPML Plugin update, ALL Page Builder strings are missing from String translation.

We tried all your troubleshooting tools. Nothing helped.

Also, we ran the "scan MO. files" which was prompted by WPML.

Please help.

Thank you,

Noam Kroll

October 25, 2019 at 9:43 am #4825655

George Botsev
Supporter

Languages: English (English )

Timezone: Europe/Sofia (GMT+03:00)

Hello!
This is normal behaviour.
As of the latest versions of WPML and WPML String Translation 3.x the page builder strings will not be shown in the WPML > String Translation interface.
They were never meant to be accessed from there and translating them from there creates more problems than worth.

October 25, 2019 at 9:57 am #4825719

noamK-2

Hello George,

This is very bad.

We are currently encountering an issue that keeps repeating for years:

Strings inside page builder are duplicated in a way that enforces you to re-translate the new duplicated string and then delete the "old" already translated string.

This all happens inside the classic translation editor.

The only way to deal with it, and this has been verified with your support (Amit Kvint was involved) is to delete the "old" strings on String Translations.

See this screenshot for example (current situation): hidden link

Thank you,

Noam Kroll

October 25, 2019 at 2:41 pm
October 25, 2019 at 2:53 pm #4827843

noamK-2

Hello George,

Thank you,

But I am not sure I understand what you are saying.

1. Now that WPML changed how the strings work - is there no legitimate way to solve the duplicate strings issue? If this is the case, this needs to be communicated immediately to Amir and Amit. This is a major drawback.!!

2. Regarding this hack - What does it do? You did not explain. Does it bring back the missing strings into the Strings Translation?

Or does it delete only this specific string I showed you?

Or does it do something else?

3. How can I tackle the rest of the duplicate strings?

4. What happens with the next plugin update? Will we need to repeat this hack.

We are confused!! Duplicate strings are a well known phenomena with WPML, that has never been completely resolved. Many users have complained about this issue over the years.

It could have been dealt with through String Translation, but not anymore. What should we do now?

Thank you,

Noam Kroll

October 25, 2019 at 3:07 pm #4827951

George Botsev
Supporter

Languages: English (English )

Timezone: Europe/Sofia (GMT+03:00)

About point 1 - I did not check for that issue. You told me that Amit already knows about it and that you have been like that:

We are currently encountering an issue that keeps repeating for years

About point 2 It will bring back the strings contexts from the page builder to string translation - from my understanding that is what you wanted in the first place by opening this ticket.

About point 3 - I cannot tell, but you said that it was happening for years and I did not investigate that case.

About point 4 - yes, on the next update the dirty hack would have to be applied again.

I just tried to help you fix the issue that you opened a ticket here -> "After recent WPML update, all Page Builder strings are missing from String trans"

October 25, 2019 at 3:18 pm #4828007

noamK-2

Hello George,

Thank you very much. Your hack seems to have worked! Appreciate it very much.!!

Regarding Amir and Amit - can you communicate the issue to them or should I email them directly?

Thanks again,

Noam Kroll

October 25, 2019 at 3:46 pm #4828159

George Botsev
Supporter

Languages: English (English )

Timezone: Europe/Sofia (GMT+03:00)

I pinged Amit about your ticket here already, but he is off right now.
I am sure that he will respond soon.

October 26, 2019 at 11:31 am #4831481

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Hello,

I'm Alejandro and i'll take over the ticket and keep you updated on the changes from now on.

We're working on it and we will probably have more information about this on monday when Both Amit and the developers that will work on this issue are present.

I only ask that you please leave the credentials you provided to us active and give us confirmation that we can take a site snapshot if needed.

Please know that i will not take a snapshot, without your consent and of course i'm only thinking ahead, to save you some time (we might not need any snapshot at all, but it's best to have this covered in case our developers do ask me for a snapshot).

As a last request, i kindly ask you to tell us which strings were not showing correctly before the hack that George provided you? and where could i find them both in the back and front-end?

Thanks in advance for your collaboration.

October 28, 2019 at 8:11 am #4836633

Amit
Supporter

Hi Noam, בוקר טוב

Amit here. I have looked at your report and just consulted with George and our developers and we'd like to please ask you for a full package of the website so we can install on our test servers and take a deeper look at what's going on. We do not have any similar issues reported from other clients at the moment, what you have there seems related to an older bug which was successfully fixed and should not be happening now, so my guess would be that there are some traces of wrong DB entries in your WP install, but this is just a guess and in order to offer a real solution and help you resolve that issue once and for all a thorough debug is needed.

I am activating the private comment box so you can share with us a duplicator for your site. After you'd share it I will prioritize that issue so we can get to the bottom of it.

Regards!

October 28, 2019 at 9:17 am #4837163

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Hello, I just wanted to let you know that the duplicator is no longer needed. i had a few issues woth the one you provided us before so i created a new one and i believe we have all we need now.

I already escalated the issue to our development team with all the details you have provided us.

I'll keep you updated on the news they give me.

October 28, 2019 at 1:09 pm #4839799

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Hi there,

I just wanted to let you know that i believe we have found the issue and also how to fix it. I'm asking for specifics so i can give you a very specific answer on why the problem happened and how to fix it.

I'll update you shortly.

October 28, 2019 at 1:55 pm #4840409

noamK-2

Hello Alejandro,

Thank you very much for the update.

Please note that duplicate strings inside the classic translation editor, keep occurring from time to time (however, we couldn't identify any predictive pattern).

Your support promised a few times in the past to come up with a solution, but failed to do so. I guess it was hard to find the reasons behind it - besides cliches like conflicts with other plugins etc.

You can see what other users are saying:

https://wpml.org/forums/topic/duplicate-strings/

https://wpml.org/forums/topic/many-duplicate-strings-for-same-translation/

https://wpml.org/forums/topic/duplicated-translation-strings/

And many more.

Thank you,

Noam Kroll

October 28, 2019 at 4:20 pm #4841613

Alejandro
Supporter

Languages: English (English ) Spanish (Español ) Italian (Italiano )

Timezone: Europe/Rome (GMT+02:00)

Hi there, i see and understand. our developers are still looking into it. It does seem to be a very particular case and we had a few cases that sounded exactly alike yet they turned out to be completely different, but i have made notice of the older links you have pointed out so to see if the problem could be the same or not.

I'll update you once i have more information on this subject, hopefully now will be the time we solve this mistery once and for all.

In the meantime i Thank you for your patience.

November 5, 2019 at 4:11 pm #4891389

Pierre
Supporter

Languages: English (English ) French (Français ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi Noam,

I am Pierre from WPML dev team. We've investigated your site and we found some inconsistencies in the database. Some page builder strings have a corrupted name and this prevent WPML to automatically remove it when the post content is parsed.

At this point, we can't tell how those strings could get corrupted.

However, I prepared a script to fix the strings in the database: Some duplicates will be deleted and corrupted names will be fixed.

Before anything, please take a full backup of your site!

Here's the snippet that you need to paste in your theme's functions.php file:

/**
 * Fix corrupted page builder package strings (wrong name and/or duplicates).
 *
 * @see <em><u>hidden link</u></em>
 */
function wpmlcore_6913_fix_corrupted_package_strings() {
	global $wpdb;

	// Will collect all package string with a wrong name.
	$allCorrupted = wpml_collect( $wpdb->get_results(
		"SELECT
			s1.id,
			s1.string_package_id,
			s1.value,
			s1.name,
			s2.id AS duplicate_of_valid_id
		FROM {$wpdb->prefix}icl_strings AS s1
		LEFT JOIN {$wpdb->prefix}icl_strings AS s2 ON s2.name = MD5(s1.value)
		WHERE s1.string_package_id IS NOT NULL
			AND s1.name <> MD5(s1.value)
		ORDER BY s1.id"
	) )->keyBy( 'id' );

	if ( ! $allCorrupted->count() ) {
		return;
	}

	// duplicated string of a valid one => to delete
	$duplicatesOfNonCorrupted = $allCorrupted->filter( function( $string ) { return (bool) $string->duplicate_of_valid_id; } );
	// duplicated string with no valid one => keep the latest version and remove the other duplicates
	$corruptedDuplicates = $allCorrupted->diffKeys( $duplicatesOfNonCorrupted );

	// We'll keep the highest string id only
	$duplicatesToKeepAsUnique = $corruptedDuplicates
		->reduce( function( \WPML\Collect\Support\Collection $carry, $string ) {
			// Duplicated value/package_id will be overwritten.
			$key = md5( $string->string_package_id . $string->value );
			$carry->put( $key, $string );

			return $carry;
		}, wpml_collect() )
		->keyBy( 'id' );

	$duplicatesToDelete = $corruptedDuplicates->diffKeys( $duplicatesToKeepAsUnique );
	$stringIdsToDelete  = $duplicatesOfNonCorrupted->merge( $duplicatesToDelete )->pluck( 'id' )->toArray();

	if ( $stringIdsToDelete ) {
		wpml_unregister_string_multi( $stringIdsToDelete );
	}

	if ( $duplicatesToKeepAsUnique->count() ) {
		$wpdb->query(
			"UPDATE {$wpdb->prefix}icl_strings
		SET
			name = MD5(value),
			domain_name_context_md5 = MD5(CONCAT(context,MD5(value),gettext_context))
		WHERE id IN(" . $duplicatesToKeepAsUnique->implode( 'id', ',' ) . ")"
		);
	}
}
add_action( 'admin_footer', 'wpmlcore_6913_fix_corrupted_package_strings' );

Then visit the admin dashboard once. And when it's done, just remove the snippet.

Now, if you create a new job for your page (do some update in the original or send a job from the translation dashboard), you should not see duplicated fields anymore.

If you don't feel comfortable to apply the fix, just ask me to do it.

Let me know if this helps.

Thanks,
Pierre