Conditional Shortcode Based on Language

Things like emails sent to users by different plugins cannot be translated because they do not appear in the front-end.

For these other types of content you can display content based on language using the shortcode:

[trp_language language="en_US"] English content only [/trp_language]

This can be done also with PHP:

<?php
    $current_language = get_locale();

    if( $current_language == 'en_EN' ){
      echo 'text in language en_EN';
    }
    
    if( $current_language == 'fr_FR' ){
      echo 'text in language fr_FR';
    }
    
?>

Another use case of the conditional shortcode is for translating images, basically displaying different images for different languages.

[trp_language language="en_US"] 
<‍img src="https://example.com/image_en.png" /> [/trp_language]
[trp_language language="fr_FR"]
<‍img src="https://example.com/image_fr.png" />
[/trp_language]

However, this can now be easily achieved directly from the front-end using the built in image translation functionality.

Elementor Integration

TranslatePress is fully compatible with Elementor, so if your website is built using Elementor, you can achieve the same functionality for widgets and sections directly from Elementor’s interface.

Restrict by Language

To use this option click on a widget or section and then go to the Advanced tab, where you’ll find the Restrict by Language option. Set the option to Yes and select the language in which you’d like to show the selected element.

Exclude from Language

Through Elementor an extra option is provided, Exclude from Language, through which you can make an element show in all languages, except the one(s) that you selected.