Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi @nixxxon23,

    As per the current version of the plugins, the emails are made WPML compatible and they appear in the string translation section of WPML so you do need to use a hook.

    You can simply go to WPML String translation and scan for the string. Once done, the user registration strings will show up and you can simply translate from there.

    Regards!

    Thread Starter NixXxon23

    (@nixxxon23)

    Hello,
    thanks for the fast reply. For me it doesn’t work out of the box.
    Maybe because I set a custom message in your plugins settings? I don’t know how to reset this to default without deleting the plugin…

    I translated the desired string in WPML and tested with a user who’s language is set to English but I still receive the german mailtext which I set in the settings.

    Thank you for your support!

    Best,
    Niko

    Thread Starter NixXxon23

    (@nixxxon23)

    I did a bit more testing and found out that the translation per se works BUT it uses the “admin language” and not the users language. It ignores “icl_admin_language”.

    https://prnt.sc/s4o1qq –> User would receive an german mail.

    If you could give me an code example how to hook in your mails and implement it with WPML it would be great.
    https://wpml.org/documentation/support/sending-emails-with-wpml/

    I just need need one example and can do the rest of the mails by myself.

    Thread Starter NixXxon23

    (@nixxxon23)

    I did it. It would be great if you could add this in one of your future updates.
    First of all the users needs the meta key icl_admin_language.

    So I added this code to my functions.php

    
    add_action( 'user_register', 'biog_registration_save', 20, 1 );
    
    function biog_registration_save( $user_id ) {
    	$lang = ICL_LANGUAGE_CODE;
        if ( isset( $lang ) )
            add_user_meta($user_id, 'icl_admin_language', $lang );
    	else
    		add_user_meta($user_id, 'icl_admin_language', 'de' );
    
    }
    

    Then I edited your file: class-ur-mailer.php

    
    public static function lost_password_email( $user_login, $user_data, $key ) {
    
    		$user     = get_user_by( 'login', $user_login );
    		$email    = isset( $user->data->user_email ) ? $user->data->user_email : '';
    		$username = isset( $user->data->user_login ) ? $user->data->user_login : '';
    
    		if ( empty( $email ) || empty( $username ) ) {
    			return false;
    		}
    		do_action('wpml_switch_language_for_email', $email); //todo check if funcion exists
    
    		$subject = get_option( 'user_registration_reset_password_email_subject', __( 'Password Reset Email: {{blog_info}}', 'user-registration' ) );
    		$message = new UR_Settings_Reset_Password_Email();
    		$message = $message->ur_get_reset_password_email();
    		$message = get_option( 'user_registration_reset_password_email', $message );
    
    		$values = array(
    			'username' => $username,
    			'email'    => $email,
    			'key'      => $key,
    		);
    
    		$message = self::parse_smart_tags( $message, $values );
    		$subject = self::parse_smart_tags( $subject, $values );
    
    		if ( 'yes' === get_option( 'user_registration_enable_reset_password_email', 'yes' ) ) {
    			
    			wp_mail( $email, $subject, $message, self::ur_get_header() );
    			do_action('wpml_switch_language_for_email', $email); //todo check if funcion exists
    			return true;
    		}
    
    		return false;
    	}
    

    I added just 2 lines
    1st one before the email is send:
    do_action(‘wpml_switch_language_for_email’, $email);
    2nd after the mail is sent to switch the language back
    do_action(‘wpml_switch_language_for_email’, $email);

    Of course I did this for all mails. This is just an example.

    This will only work for users who have WPML installed!

    Would be great if you could notify me if you add this to one of your future updates.

    BR;
    Niko

    • This reply was modified 4 years, 7 months ago by NixXxon23.

    Hi @nixxxon23,

    I am glad that you found out. Also, I will make sure to let you know if we add this snippet in our core.
    Have a great day. ??

    Regards!

    Hi @nixxxon23,

    I have the similar issue but the code didn’t work. I also, tried to manually set the Spanish version of the email using user_registration_get_email_confirmation hook. but didn’t work. Any ideas?

    Here is what I tried.

    
    add_filter('user_registration_get_email_confirmation', 'change_email_content_test');
    function change_email_content_test( $message ) {
    $message = 'modified text example';
    return $message;
    }
    

    Any ideas?
    Thanks

    Thread Starter NixXxon23

    (@nixxxon23)

    Hi,
    do you use WPML?
    I’m not sure if the plugin uses “user_registration_get_email_confirmation”? Maybe the plugin author can help.

    My workaround solution is really just for users with WPML installed.

    Do you need your text JUST in spanish or in 2 different languages? If you just need it in Spanish you can edit the mailtest in the Plugin Settings ??

    BR,
    Niko

    Hi @nixxxon23,

    Thanks for your respond. yes. I have WPML installed and I translated all email content using WPML string translation. Now just trying to figure it out how to send Spanish translation of the email if user registered using the Spanish as selected language. plugin always send the confirmation emails in English.

    Thanks ??

    Thread Starter NixXxon23

    (@nixxxon23)

    … OK good start. ??

    Did you try with my Code.
    1. You need to make sure that the user language is stored. You can do this with this function (This function stores the user language in the meta key “icl_admin_language” when a users signs up to your page). You can change “de” to “es” if “es” is your default language.:

    add_action( 'user_register', 'biog_registration_save', 20, 1 );
    
    function biog_registration_save( $user_id ) {
    	$lang = ICL_LANGUAGE_CODE;
        if ( isset( $lang ) )
            add_user_meta($user_id, 'icl_admin_language', $lang );
    	else
    		add_user_meta($user_id, 'icl_admin_language', 'de' );
    
    }

    Then comes the dirty code. You need to edit the plugin file (make sure to make a backup of the file before and after). This file will probably replaced if you make an plugin update so you need replace this file with your edited version after every plugin update until the author adds this change to his code.

    File: …/wp-content/plugins/user-registration/includes/class-ur-mailer.php

    public static function lost_password_email( $user_login, $user_data, $key ) {
    
    		$user     = get_user_by( 'login', $user_login );
    		$email    = isset( $user->data->user_email ) ? $user->data->user_email : '';
    		$username = isset( $user->data->user_login ) ? $user->data->user_login : '';
    
    		if ( empty( $email ) || empty( $username ) ) {
    			return false;
    		}
    		do_action('wpml_switch_language_for_email', $email); //todo check if funcion exists
    
    		$subject = get_option( 'user_registration_reset_password_email_subject', __( 'Password Reset Email: {{blog_info}}', 'user-registration' ) );
    		$message = new UR_Settings_Reset_Password_Email();
    		$message = $message->ur_get_reset_password_email();
    		$message = get_option( 'user_registration_reset_password_email', $message );
    
    		$values = array(
    			'username' => $username,
    			'email'    => $email,
    			'key'      => $key,
    		);
    
    		$message = self::parse_smart_tags( $message, $values );
    		$subject = self::parse_smart_tags( $subject, $values );
    
    		if ( 'yes' === get_option( 'user_registration_enable_reset_password_email', 'yes' ) ) {
    			
    			wp_mail( $email, $subject, $message, self::ur_get_header() );
    			do_action('wpml_switch_language_for_email', $email); //todo check if funcion exists
    			return true;
    		}
    
    		return false;
    	}

    The lost password mail is just an example. You need to add these 2 lines (see above and below example) for every mail you want to translate.

    • do_action(‘wpml_switch_language_for_email’, $email); –> add this before the $subject to switch the languague to the users language
    • do_action(‘wpml_switch_language_for_email’, $email); –> add this after wp_mail( $email,… to change the language back to default language
    • After this is done you can translate the strings in WPML and everything should work as expected. But only for newly registred users because “old” users do not have the meta key “icl_admin_language” set yet.

      Hope this helps. Hope you understand that I can’t support much further here because thats not my plugin and I do not eary anything but Karma for this ??

      BR,
      Niko

    • This reply was modified 4 years, 6 months ago by NixXxon23.
    • This reply was modified 4 years, 6 months ago by NixXxon23. Reason: formatting
    • This reply was modified 4 years, 6 months ago by NixXxon23.
    Dexter800

    (@punxsutawney-phil)

    Thank you @nixxxon23, you saved my life! I really really thank you, man.
    Please developers, add that code to the next release, it would be so cool.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Translate Mailtext’ is closed to new replies.