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 7 years, 6 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.
Our next available supporter will start replying to tickets in about 0.38 hours from now. Thank you for your understanding.
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)
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.
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:
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.
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