Skip Navigation

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

Problem:
The client needs to change the language of over 400 posts that were incorrectly duplicated and translated within the same language instead of being assigned to their respective German and Spanish versions.

Solution:
We recommend the following steps:
1. Make a database backup.
2. Export the posts to CSV files for each language using WP All Export and WPML documentation.
3. Delete all the posts from all languages and remove them from the trash.
4. Import them again, ensuring to select the proper language during the import process as outlined in the WPML All Import documentation.

If this solution does not seem relevant to your situation, please open a new support ticket in the 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 3 replies, has 2 voices.

Last updated by Bruno Kos 10 months, 3 weeks ago.

Assisted by: Bruno Kos.

Author Posts
January 25, 2024 at 10:38 am #15225538

Boris

Hi,
I am in the process of troubleshooting a website which was set up with WPML improperly:

There are over 400 English CPT posts. Each of these has been translated both to German and Spanish. But not in the correct way: they simply duplicated the post within English (the CPT was until now not set up to be translatable), translated the content and named it "Post A German", "Post A Spanish", etc.
I now want to migrate all of those German and Spanish versions to their proper language, and connect them to their English counterpart.

Since there are over 400, this is a lot of work. Do you know of any way to change the language of these posts in bulk? I will still have to reconnect them, but it would still save a lot of time.

Thank you for your help!
Kind regards,
Boris

January 25, 2024 at 11:59 am #15225990

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

Hi,

Thank you for contacting WPML support!

What if you try this approach:

1) make a database backup
2) export them to their respective languages, so 1 CSV file for each
https://wpml.org/documentation/plugins-compatibility/export-multilingual-websites-using-wp-all-export-wpml/#Exporting-Multilingual-Websites
3) delete all 400 from all languages and remove them from the trash
4) import them again like this: https://wpml.org/documentation/related-projects/wpml-all-import-plugin-website-import-with-wpml/importing-multiple-languages-with-wp-all-import-and-wpml/#import-the-default-language-file, make sure to select the proper language

This will ensure you changed their language and these will be connected after that also.

Regards,
Bruno Kos

January 25, 2024 at 2:09 pm #15226666

Boris

Hi Bruno,
that's a nice idea, but the CPT's for all three languages have been created in WPML set to English, so I can only export them all at once. They are all in one big list (1,264 items)...

Currently, I'm opening each one invididually and changing the language, then connecting them to the English counterpart.

January 25, 2024 at 2:49 pm #15226787

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

I see - in this case it would not be possible via database in a bulk either. But you can export them all to CSV and then try with Excel perhaps.

So you would need a function in Excel that recognizes the language of text in a column and exports rows with matching language to a new sheet. Note that this is just an idea and I have not tested it, so for custom solution you can check with our https://wpml.org/contractors/.

Step 1: Install the Google Translate API

To detect the language of the text, you can use the Google Translate API. You'll need to install the Google API client library for Excel. You can find instructions on how to do this in the Google Cloud documentation.

Step 2: Create a User-Defined Function (UDF) for Language Detection

In Excel, you can create a custom function (UDF) using VBA (Visual Basic for Applications) to detect the language of a given text. Here's an example of a UDF to detect the language using the Google Translate API (you need to adjust this to work with your specific API key):

Function DetectLanguage(text As String) As String
    Dim xhr As Object
    Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    
    Dim apiKey As String
    apiKey = "YOUR_API_KEY_HERE" ' Replace with your API key
    
    Dim url As String
    url = "<em><u>hidden link</u></em>" & apiKey
    
    Dim postData As String
    postData = "{""q"": """ & text & """}"
    
    xhr.Open "POST", url, False
    xhr.setRequestHeader "Content-Type", "application/json"
    xhr.send postData
    
    Dim response As String
    response = xhr.responseText
    
    Dim language As String
    language = Split(Split(response, """language"":""")(1), """")(0)
    
    DetectLanguage = language
End Function

Step 3: Use the UDF to Detect Language

In your Excel workbook, you can use the `DetectLanguage` function to determine the language of the text in a specific column (e.g., column A). Let's assume you want to detect the language in column A and export matching rows to a new sheet named "English Rows." Here's a sample formula to place in a cell in your new sheet:

`=IF(DetectLanguage(Sheet1!A2) = "en", Sheet1!A2, "")`

This formula will return the text if it's in English (you can change "en" to any other language code you want to detect).

Step 4: Filter and Copy Matching Rows

After you have used the formula to identify rows with the desired language, you can filter and copy the matching rows to a new sheet manually or by using a macro.

Step 5: Create a Macro to Automate the Process

To automate the process, you can record a macro while manually filtering and copying rows. Then, modify the macro to work with your specific criteria and sheets. You can assign this macro to a button or a keyboard shortcut for easy access.

Please note that the example provided is a simplified demonstration. Implementing the Google Translate API in Excel may require additional setup and customization based on your specific needs and data structure. Additionally, you will need a Google Cloud account and API key to access the Google Translate API.

January 25, 2024 at 3:22 pm #15227054

Boris

Hi Bruno,
thank you for thinking with me. I think I can work out something like this. And thanks for pointing me to the contractors, I'm actually one of them myself 🙂 and was just wondering if there was a better way to go about this process than one-by-one manual labour.
Thanks again for your always-high-quality support and have a nice day!
Kind regards,
Boris Hoekmeijer