Skip Navigation

[Resolved] Translate password reset form

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

Problem:
How to Translate forgot password form placeholder texts, form validation errors and form submission error message, if we are using [wpv-forgot-password-form] in the website.

Solution:
Please add below code in your theme’s or child theme’s functions.php file. The $translated_text contains the text string which you can change with your own translated text:

add_filter('gettext', 'mycustom_func', 10, 3);
function mycustom_func($translated_text, $text, $domain){
 
        if($text == 'Username or Email'){
            $translated_text = 'Benutzername';
        }
        elseif($text == 'Get New Password'){
            $translated_text = 'Passwort zurücksetzen';
        }
        elseif( strpos( $text, 'Invalid username or email') !== false ){
            $translated_text = 'Falscher Benutzername oder Email.'; 
        }
        elseif(  strpos( $text, 'ERROR') !== false ){
            $translated_text = 'Fehler: ';  
        }
        elseif(  strpos( $text, 'Enter a username or email address') !== false ){
            $translated_text = 'Enter Benutzername oder Email ';    
        }
        return $translated_text;
       }

Relevant Documentation:
==> strpos function finds the position of the first occurrence of a substring (text) in a string and !== false is needed for this purpose. You can check more details for the strops function here: http://php.net/manual/en/function.strpos.php

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 11 replies, has 2 voices.

Last updated by Nicholas 6 years, 11 months ago.

Assisted by: Noman.

Author
Posts
#514249

Hello. I've read through the following topics:
https://toolset.com/forums/topic/translation-for-validation-messages-in-login-form-remember-password-form/
https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
https://toolset.com/forums/topic/change-sorry-that-username-already-exists-message/
https://toolset.com/forums/topic/translate-mail-output-reset-password-form/
https://toolset.com/forums/topic/wpv-forgot-password-form-translation-not-being-translated/
https://toolset.com/forums/topic/custom-forgot-password-formpage-instead-of-default-wordpress-page/

Unfortunately I wasn't able to get the translations to work.
I put the following in my functions.php file

add_filter('gettext', 'mycustom_func', 10, 2);
function mycustom_func($translated_text, $domain){
    if($domain != 'wpv-views') return $translated_text;
    if($translated_text == 'Username or Email'){
        $translated_text = 'Benutzername';
    }
    if($translated_text == 'Get New Password'){
        $translated_text = 'Passwort zurücksetzen;
    }
    return $translated_text;
}

Please help.

#514290

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Nicholas,

Thank you for contacting Toolset support.

1. Can you please provide us step by step details that how you have created the Form and translated the messages in Form? (preferably with back-end screenshots)

2. What you expected to see on the front page?
3. What you actually see. (preferably with front-end screenshot and Link)

Also can you please share your Debug Information with us so we can see it? I have enabled debug info box for your next reply:
https://toolset.com/faq/provide-debug-information-faster-support/

Looking forward to help you.
Thank you

#514310
reset form.png

I used [wpv-forgot-password-form] and [wpv-reset-password-form] on different pages.

I expected to see the following translated :

add_filter('gettext', 'mycustom_func', 10, 2);
function mycustom_func($translated_text, $domain){
    if($domain != 'wpv-views') return $translated_text;
    if($translated_text == 'Username or Email'){
        $translated_text = 'Benutzername';
    }
    if($translated_text == 'Get New Password'){
        $translated_text = 'Passwort zurücksetzen';
    }
    return $translated_text;
}

+ the ERROR Message.
However it is not translated: see screenshot.

#514422

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Nicholas,

I have tried this to translate using this shortcode [wpv-forgot-password-form] in initial testing and its not working for me. I am still working on this issue and will get back to you soon.

Thank you for your patience.

#514438

Thank you for looking in to this:

I'd like to translate the following:

add_filter('gettext', 'mycustom_func', 10, 2);
function mycustom_func($translated_text, $domain){
    if($domain != 'wpv-views') return $translated_text;
    if($translated_text == 'Username or Email'){
        $translated_text = 'Benutzername';
    }
    if($translated_text == 'Get New Password'){
        $translated_text = 'Passwort zurücksetzen';
    }
    return $translated_text;
}
add_filter('wpv_filter_override_auth_errors', 'my_translation_func', 10, 3);
function my_translation_func($error_string, $wp_error, $fail_reason){
    if($fail_reason == 'incorrect_password'){
        $error_string = 'Falsches Passwort';
    }
    return $error_string;
}
add_filter( 'gettext', 'Translate_mail_func', 20, 3 );
/**
 *
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 */
function Translate_mail_func( $translated_text, $text, $domain ) {
    if ( $domain == 'wpv-views' ) {
        switch ( $translated_text ) {
            case 'Someone has requested a password reset for the following account:' :
                $translated_text = __( 'Eine Anfrage auf ein neues Passwort wurde gestellt:', 'theme_text_domain' );
                break;
            case 'Username: %s.' :
                $translated_text = __( 'Benutzername: %s.', 'theme_text_domain' );
                break;
            // here  add more translations.
        }
    }
    return $translated_text;
}
function wpv_filter_wpv_replace_retrieve_password_email_body( $message, $key, $user_login, $user_data ) {
    $reset_password = '';
 
    if(
        isset( $_REQUEST['wpv_forgot_password_form_reset_password_url'] )
        && !empty( $_REQUEST['wpv_forgot_password_form_reset_password_url'] )
    ) {
        $reset_password = add_query_arg(
            array(
                'action' => 'rp',
                'key' => $key,
                'login' => rawurlencode( $user_login )
            ),
            $_REQUEST['wpv_forgot_password_form_reset_password_url']
        );
 
        // Create new message
        $message  = __( 'Someone has requested a password reset for the following account:', 'wpv-views' ) . "\r\n\r\n";
        $message .= sprintf( __( '%s.', 'wpv-views' ), get_home_url() ) . "\r\n\r\n";
        $message .= sprintf( __( 'Username: %s.', 'wpv-views' ), $user_login ) . "\r\n\r\n";
        $message .= __( "If this was a mistake, just ignore this email and nothing will happen.", 'wpv-views' ) . "\r\n\r\n";
        $message .= __( 'To reset your password, visit the following address:', 'wpv-views' ) . "\r\n\r\n";
        $message .= sprintf( __( '%s', 'wpv-views' ), $reset_password ) . "\r\n\r\n";
    }
 
    return $message;
}
#514455

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Nicholas,

For [wpv-forgot-password-form] I have modified the code and its working good now. Please add below code in your theme’s or child theme’s functions.php file and it should work fine:

add_filter('gettext', 'mycustom_func', 10, 2);
function mycustom_func($translated_text, $domain){
    if($translated_text == 'Username or Email'){
        $translated_text = 'Benutzername';
    }
    if($translated_text == 'Get New Password'){
        $translated_text = 'Passwort zurücksetzen';
    }
    return $translated_text;
}

- I have removed this line to make it work, you can also do same for other codes where you see any similar if condition:

 if($domain != 'wpv-views') return $translated_text;

Please kindly open a new ticket for the other problems and we will try to help you to resolve this issue as well. This will help other users with similar problems to find solutions when searching the forum, I am not allowed to handle multiple issues in the same ticket.

Have a great day,
Thank you for your co-operation

#514473

It almost worked. The text: "ERROR: Invalid username or email." is still not translated.
Even though I tried the following:

add_filter('gettext', 'mycustom_func', 10, 2);
function mycustom_func($translated_text, $domain){
    if($translated_text == 'Username or Email'){
        $translated_text = 'Benutzername oder Email';
    }
    if($translated_text == 'Get New Password'){
        $translated_text = 'Passwort zurücksetzen';
    }
    if($translated_text == 'ERROR: Invalid username or email.'){
        $trasnlated_text = 'Fehler: Falscher Benutzername oder Email';
    }
    return $translated_text;
}
#514784

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Nicholas,

I have updated the code:

// Translate or change text for shortcode [wpv-forgot-password-form]
add_filter('gettext', 'mycustom_func', 10, 3);
function mycustom_func($translated_text, $text, $domain){
	if($domain == 'wpv-views') {
		if($text == 'Username or Email'){
			$translated_text = 'Benutzername';
		}
		elseif($text == 'Get New Password'){
			$translated_text = 'Passwort zurücksetzen';
		}
		elseif( strpos( $text, 'Invalid username or email') !== false ){
			$translated_text = 'Falscher Benutzername oder Email.';	
		}
		elseif(  strpos( $text, 'ERROR') !== false ){
			$translated_text = 'Fehler: ';	
		}
		return $translated_text;
	}
  }

Thank you

#514802

Thank you. I noticed that you added

if($domain == 'wpv-views')

back in. Why?

Also what does "strpos" mean and !==false in that context??

Regards,
Nicholas

#514834

Also the code works on the frontend but breaks the wp admin.

#514886

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Nicholas,

I changed the if condition slightly but looks like that causing backend text issues so I have removed it now. Please use below updated code and it will work fine. The text in the last section is if someone submits an empty form and they see an error message:

add_filter('gettext', 'mycustom_func', 10, 3);
function mycustom_func($translated_text, $text, $domain){

		if($text == 'Username or Email'){
			$translated_text = 'Benutzername';
		}
		elseif($text == 'Get New Password'){
			$translated_text = 'Passwort zurücksetzen';
		}
		elseif( strpos( $text, 'Invalid username or email') !== false ){
			$translated_text = 'Falscher Benutzername oder Email.';	
		}
		elseif(  strpos( $text, 'ERROR') !== false ){
			$translated_text = 'Fehler: ';	
		}
		elseif(  strpos( $text, 'Enter a username or email address') !== false ){
			$translated_text = 'Enter Benutzername oder Email ';	
		}
		return $translated_text;
	
    
}

==> strpos function finds the position of the first occurrence of a substring (text) in a string and !== false is needed for this purpose. You can check more details for the strops function here: hidden link

Thank you

#516405

Thank you Noman.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.