[Resolved] Best practice to replace a word sitewide
This thread is resolved. Here is a description of the problem and solution.
Problem: The client needs to replace the word 'aluminium' with 'aluminum' sitewide in the original English text without affecting the translations in other languages like German or French. They are concerned that using a search and replace tool might cause WPML to forget some of the previously translated texts or break translations and pages. Solution: We recommend not using a search and replace tool on the entire database to minimize risks. Instead, manually edit an entry in the database where 'aluminium' is present and change it to 'aluminum'. Then, check if it has any implications on the translations. It is crucial to perform this on a copy of your site and ensure you have a full backup of your site before proceeding. If you decide to use the Better Search Replace plugin, it operates on the site's DB and replaces text directly in the site's DB, thus no update for the translations will be triggered unless you click the Save/Update button on the posts and pages. You can experiment with this approach using a test site provided by WPML.
If this solution does not apply to your case, or if it 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 further assistance is needed, 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.
Background of the issue:
We would like to replace a single word sitewide: aluminium to aluminum. It's in the original English but also many translations. Possible also in some slugs. We fear that if we use something like Better Search & Replace it will at least make WPML forget some of the previously translated texts. Or, at worst, forget many texts and potentially break translations and pages.
Symptoms:
We fear that using a search and replace tool might make WPML forget some of the previously translated texts or break translations and pages.
Questions:
Is there a best practice to do a simple search & replace sitewide?
I don't know any best practices for using search and replace sitewide. I suggest you take a backup of your site and try it. Or better yet, try it on a copy of your site before you try it on the production site. This matter is out of the scope of our support forum. If the word "aluminium" also shows in the translations, then, to the best of my knowledge, it should also be replaced in the translation. Then, in my opinion, if you don't "touch" the wp_icl_ tables (WPML's DB tables), there should be no problem with breaking or losing the translations. I've never tried such a thing. Please do you experiments with that.
**** Important! Please make a full site backup (files and DB) before you proceed with those steps****
However, please know that WPML's Advanced Translation Editor has a great feature called "Glossary". WPML’s glossary lets you create better translations by defining how you want certain words to appear in your site’s translations. You can read about it here.
The glossary is not a solution for what you are trying to achieve. However, it is a solution for keeping the word "aluminium" the same in the translations.
I double checked with the team. We only need to update the term aluminium to aluminum in English and NOT update any of the translations like German or French.
My main worry is that a search & replace will make the ATE memory forget about many lines of translations. And that in the future we will need to do a small update and then see big chunks of pages being empty in the ATE, resulting in lost time and frustration. This has happened many times before and we really want to avoid it happening again.
The best approach is to make an experiment to minimize risks. Don't use Search & Replace on the entire DB of your site. Manually edit one of the entries in DB where "aluminium" is present, and change it to "aluminum". Then, check if it has any implications on the translations. I suggest you do that on a copy of your site and take a backup of your site before doing that.
**** Important! Please make a full site backup (files and DB) before you proceed with those steps****
I'm surprised (and a bit annoyed to be honest) that you don't know what to expect when we change a single word in our original text. Of course that will wipe out the translation of that sentence. I've seen it happen dozens of times and it has cost me many many hours of my life already. And will continue to do so 🙁
See the attached screenshot for clarification.
It really is an annoying shortcoming in the ATE. I suppose there is no workaround? Then I'll have to manually input our translations again (looking them up on the live site).
Indeed, it is expected that when you make a change to the original post, WPML will detect this change and trigger an update for the translation. In this case, the user will only need to update the sentence where you made the change. This is to avoid the user needing to translate the entire page again. If you don't want the translation to be updated at all, you can select the option "Minor edit" before saving/updating the page or post. Please see the attached screenshot Minor-edit.jpg.
However, you talked about using the plugin Better Search Replace. This plugin operates on the site's DB. (Based on my understanding of your need, you will run it on the wp_posts DB table.) It replaces what the user needs to replace directly in the site's DB. Thus, no update for the translations will be triggered unless you click the Save/Update button on the posts and pages. I've just tried it on my test site and can confirm this behavior. Here is a test site with WPML and Better Search Replace that you can experiment with.
hidden link
With the above link, you will be directly logged in.