Last updated on October 18, 2023

WPML translation not updating

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Ensure your WPML translations update correctly.

In some cases, you may encounter an issue where WPML translations are not updating properly on your WordPress website. This can be frustrating, especially if you have made changes to your content and they are not reflected in the translated versions.

To troubleshoot this issue, you can try the following steps:

  1. Clear WPML cache: WPML has its own cache system that stores translations for faster retrieval. Clearing this cache can sometimes resolve translation update issues. You can do this by navigating to WPML -> Support -> Troubleshooting and clicking on the “Clear the cache in WPML” button.

  2. Check translation settings: Ensure that the translation settings for your content are properly configured. You can do this by going to WPML -> Translation Management and checking the settings for the affected content types.

  3. Resave the content: Resaving the content can trigger WPML to update the translations. You can do this by editing the content and simply clicking the “Update” button without making any changes. This will force WPML to reprocess the content and update the translations.

If the above steps do not resolve the issue, you can try the following code snippet as a workaround:

function wpsnippets_force_translation_update( $post_id ) {
    if ( function_exists( 'wpml_update_translations_in_post' ) ) {
        wpml_update_translations_in_post( $post_id );
    }
}
add_action( 'save_post', 'wpsnippets_force_translation_update' );

This code snippet hooks into the save_post action and calls the wpml_update_translations_in_post() function to force WPML to update the translations whenever a post is saved. Simply add this code to your theme’s functions.php file or a custom plugin file.

Please note that this code snippet is a workaround and should be used as a last resort if other troubleshooting steps fail. It may have performance implications, so use it with caution.

I hope this helps in resolving the issue with WPML translations not updating properly on your WordPress website.

Examples

Example #1: Updating WPML translation using icl_translate

This example demonstrates how to update a WPML translation using the icl_translate function.

$translated_text = icl_translate('text-domain', 'Hello', 'fr');

In this code example, the icl_translate function is used to update the translation of the string “Hello” in the French language. The translated text is stored in the variable $translated_text.

Example #2: Updating WPML translation using wpml_update_string_translation

This example shows how to update a WPML translation using the wpml_update_string_translation function.

wpml_update_string_translation('text-domain', 'Hello', 'Bonjour', 'fr');

In this code example, the wpml_update_string_translation function is used to update the translation of the string “Hello” to “Bonjour” in the French language.

Example #3: Updating WPML translation using wpml_update_woocommerce_product_translation

This example demonstrates how to update a WPML translation for a WooCommerce product using the wpml_update_woocommerce_product_translation function.

wpml_update_woocommerce_product_translation($product_id, 'fr', array(
    'name' => 'Nom du produit',
    'description' => 'Description du produit',
));

In this code example, the wpml_update_woocommerce_product_translation function is used to update the translation of a WooCommerce product with the ID $product_id in the French language. The translation includes the updated name and description of the product.

Last updated on October 18, 2023. Originally posted on October 23, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *