Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Nicolas Lemoine

    (@nlemoine)

    Hi norus,

    I don’t use WPML but I don’t think strings in the email template can be translated because they are saved with the whole template.

    Best,

    N.

    I translated my email template using the wpbe_html_body filter and preg_replace. Not elegant but it works.

    Example:

    function translate_wp_better_email_template($message){
    	if(ICL_LANGUAGE_CODE != 'fr')
    		return $message;
    
    	$message = preg_replace('/Email sent/','Courriel envoyé', $message);
    
    	return $message;
    }	add_action('wpbe_html_body','translate_wp_better_email_template');

    Plugin Author Nicolas Lemoine

    (@nlemoine)

    Hi,

    Here are some ways I thought to translate strings in template.

    Using the custom template tags:

    add_filter('wpbe_tags', function( $tags ) {
    
    	// Set the current language, fallback to english by default
    	$lang = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : 'en';
    
    	// Set a translations array
    	$translations = array(
    		'footer.email_sent_on' => array(
    			'en' => 'Email sent on',
    			'fr' => 'Email envoyé le',
    		),
    		'footer.mention' => array(
    			'en' => 'Please only print this email if necessary',
    			'fr' => 'N’imprimez cet email que si nécessaire',
    		),
    	);
    
    	// Create new tags
    	$tags['footer.email_sent_on'] = $translations['footer.email_sent_on'][$lang];
    	$tags['footer.mention']       = $translations['footer.mention'][$lang];
    
        return $tags;
    }

    You should then be able to use tags such as %footer.mention% and %footer.email_sent_on% in your template. They will be translated.

    Using the templates tags and the translation files:

    add_filter('wpbe_tags', function( $tags ) {
    
    	// Create new tags
    	$tags['footer.email_sent_on'] = __('Sent on', 'theme_text_domain');
    	$tags['footer.mention']       = __('Please only print this email if necessary', 'theme_text_domain');
    
    	return $tags;
    
    }

    Probably cleaner. If you don’t have a translation file, create one and load it manually.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WPML cooperation or work with the internal translations’ is closed to new replies.