Skip Navigation

[Resolved] Translate login and reset password forms, buttons and texts

This support ticket is created 2 years, 9 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 2 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2333381
toolset_recovery_password.jpg

Hi!,
I want to translate to catalan the forms: login and reset password. the buttons, texts and "check your email for confirmation link" text. I don't use WPML in this site.
I attach an screenshot.

thanks,
David

#2333463

Hi David,

Thank you for contacting us and I'd be happy to assist.

There are two ways, you can translate these text messages, without WPML:

1. Using PO/MO files.

You'll find the source .po file for the Toolset Blocks plugin at:
/toolset-blocks/vendor/toolset/toolset-common/languages/orig/views.po

You can use a tool like "POEDIT" ( ref: hidden link ) to create an .mo file from this .po file, in your target language and then place it in the folder at:
/toolset-blocks/vendor/toolset/toolset-common/languages folder.

Here is a guide on the topic of using the "POEDIT" tool:
hidden link

OR

2. You can use the "gettext" hook in a custom function, to translate those individual texts strings.
( ref: https://developer.wordpress.org/reference/hooks/gettext/ )

For example:


add_filter( 'gettext', 'custom_login_form_labels', 20, 3 );
function custom_login_form_labels( $translated_text, $text, $domain ) { 
    switch ( $translated_text ) {
        case 'Username or Email' :
            $translated_text = __( 'Username or Email New Text', 'wpv-views' );
        break;
        case 'New password' :
            $translated_text = __( 'New password New Text', 'wpv-views' );
        break;
        case 'Repeat new password' :
            $translated_text = __( 'Repeat new password New Text', 'wpv-views' );
        break;
        case 'Reset Password' :
            $translated_text = __( 'Reset Password New Text', 'wpv-views' );
        break;
    }
    return $translated_text;
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

In this example, I've only included some of the strings, but you can include more cases for the other text strings as needed too.

regards,
Waqar

#2335845

Hi Waqar, your code worked fine with some texts, but not with this ones:
- ERROR: The username field is empty.
- ERROR: The password field is empty.
- ERROR: There is no user registered with that email address.

how can I know the exact string to pass to gettex function?

thanks,
David

#2336805

Thanks for writing back.

In these messages, the word "ERROR" is a separate string from the rest of the text, so it will need to be translated that way too.

Example:


add_filter( 'gettext', 'custom_login_form_labels', 20, 3 );
function custom_login_form_labels( $translated_text, $text, $domain ) { 
    switch ( $translated_text ) {
        case 'ERROR' :
            $translated_text = __( 'NEW ERROR', 'wpv-views' );
        break;
        case 'The password field is empty.' :
            $translated_text = __( 'NEW The password field is empty.', 'wpv-views' );
        break;
        case 'The username field is empty.' :
            $translated_text = __( 'NEW The username field is empty.', 'wpv-views' );
        break;
        case 'There is no user registered with that email address.' :
            $translated_text = __( 'NEW There is no user registered with that email address.', 'wpv-views' );
        break;
        
    }
    return $translated_text;
}

Tip: To quickly look for specific words/text in all the files of any plugin, you can download a free text editor "Sublime Text" ( ref: hidden link ) and use the "Find in files" feature.
( ref: hidden link )