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
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
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
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 )