- This topic has 11 replies, 2 voices, and was last updated 3 years, 3 months ago by
Fernando.
-
AuthorPosts
-
December 6, 2022 at 10:18 am #2451807
Vladimir
Hi,
Can you please send me instructions on where do I change (I want to translate) these 5 field names and 1 button for the blog comment form:
https://share.getcloudapp.com/6quNL462I am using your premade theme READ.
Thank you,
Vlad
December 6, 2022 at 5:24 pm #2452236Fernando Customer Support
Hi Vladimir,
You’ll need a couple of Filter hooks to alter those text.
Let’s start with “Leave a Comment”.
Add this PHP:
add_filter( 'generate_leave_comment','tu_custom_leave_comment' ); function tu_custom_leave_comment() { return 'Join the conversation'; }Replace
Join the conversationwith your translated text.Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Then for “Post Comment”. Add this:
add_filter( 'generate_post_comment ','tu_custom_post_comment' ); function tu_custom_post_comment() { return 'Post Comment customize'; }Replace
Post Comment customizewith your translated text.Now, for the Post Comment Form fields, add this:
add_filter( 'comment_form_default_fields',function($fields){ $commenter = wp_get_current_commenter(); $required = get_option( 'require_name_email' ); $fields['author'] = sprintf( '<label for="author" class="screen-reader-text">%1$s</label><input placeholder="%1$s%3$s" id="author" name="author" type="text" value="%2$s" size="30" />', esc_html__( 'Nombre', 'generatepress' ), esc_attr( $commenter['comment_author'] ), $required ? ' *' : '' ); $fields['email'] = sprintf( '<label for="email" class="screen-reader-text">%1$s</label><input placeholder="%1$s%3$s" id="email" name="email" type="email" value="%2$s" size="30" />', esc_html__( 'Correo Eléctronico', 'generatepress' ), esc_attr( $commenter['comment_author_email'] ), $required ? ' *' : '' ); $fields['url'] = sprintf( '<label for="url" class="screen-reader-text">%1$s</label><input placeholder="%1$s" id="url" name="url" type="url" value="%2$s" size="30" />', esc_html__( 'Website', 'generatepress' ), esc_attr( $commenter['comment_author_url'] ) ); $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"'; $fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' . '<label for="wp-comment-cookies-consent">TEXT FOR CHECKBOX HERE</label></p>'; return $fields; }, 15, 1);Replace
Nombre,Correo Eléctronico, andWebsitewith your translated texts.Let us know how it goes.
December 6, 2022 at 8:25 pm #2452345Vladimir
This is great code and this worked well as you can see here. There is just one more field that I pointed out in the screenshot when I submitted the ticket that you didn’t do the code for and this is the “checkbox” on the bottom which says:
Save my name, email, and website in this browser for the next time I comment.
Can you please send me code for that.
December 6, 2022 at 8:51 pm #2452355Fernando Customer Support
Yes, I can give you the code for that.
I updated the third code above, can you test that instead?:
Replace
TEXT FOR CHECKBOX HEREwith your translated text as well.Let us know how it goes.
December 6, 2022 at 9:02 pm #2452359Vladimir
This works great. I just implemented it. On the form conformation page, I just see another text. It says: “Your comment is awaiting moderation.” Would you mind sending me code for that also and we are done?
This is amazing how well you write this code…I wish I had this skill.
December 6, 2022 at 9:25 pm #2452367Fernando Customer Support
Yes, I can send code for that:
add_filter( 'gettext', function( $text ) { if ( 'Your comment is awaiting moderation.' === $text ) { return 'Translated Text abc'; } return $text; } );Replace
Translated Text abcwith your translated text.There’s no filter for that.
Take note that you can submit a translation for your language in WordPress here: https://translate.wordpress.org/projects/wp-themes/generatepress/
December 6, 2022 at 9:35 pm #2452377Vladimir
Thank you! Closing ticket.
December 6, 2022 at 9:47 pm #2452385Fernando Customer Support
You’re welcome, Vladimir!
December 8, 2022 at 10:01 pm #2455414Vladimir
Fernando,
Sorry to open this ticket again. I forgot to translate these 3 elements that are visible when user is logged into the website and goes to leave the comment: https://jmp.sh/eEDTrq4c
Can you please send me code for the text I highlight above the comment form and for “Post Comment” button on the bottom.
Thank you so much and sorry for reopening the ticket again.
Here is the screenshot: https://jmp.sh/eEDTrq4c
December 8, 2022 at 10:44 pm #2455444Fernando Customer Support
I see. Can you try modifying the code here: https://generatepress.com/forums/topic/how-to-translate-fieldnames-in-the-blog-comment-form/#post-2452367
To this:
add_filter( 'gettext', function( $text ) { if ( 'Your comment is awaiting moderation.' === $text ) { return 'Translated Text abc'; } else if ( 'Komentari' === $text ) { return 'Translated Text abc'; } else if ( 'Logged in as' === $text ) { return 'Translated Text abc'; } else if ( 'Edit your profile' === $text ) { return 'Translated Text abc'; } else if ( 'Log out' === $text ) { return 'Translated Text abc'; } else if ( 'Required fields are marked' === $text ) { return 'Translated Text abc'; } else if ( 'Post Comment' === $text ) { return 'Translated Text abc'; } return $text; } );Replace
Translated Text abcfor all translations.December 8, 2022 at 11:04 pm #2455451Vladimir
I entered the text you gave me as:
add_filter( ‘gettext’, function( $text ) {
if ( ‘Your comment is awaiting moderation.’ === $text ) {
return ‘Vas komentar ceka odobravanje’;
} else if ( ‘Komentari’ === $text ) {
return ‘Translated Text abc’;
} else if ( ‘Logged in as’ === $text ) {
return ‘Logirani ste kao’;
} else if ( ‘Edit your profile’ === $text ) {
return ‘Modifikujte svoj profil’;
} else if ( ‘Log out’ === $text ) {
return ‘Izlogirajte se’;
} else if ( ‘Required fields are marked’ === $text ) {
return ‘Nuzna polja su oznacena’;
} else if ( ‘Post Comment’ === $text ) {
return ‘Komentar’;
}return $text;
} );and the text you gave me successfully translated button on the form, but it did not work for this one line which is in English:
https://jmp.sh/a4hAGqvzI do see you gave me code for “Logged in as” and “Edit your profile. Log out? Required fields are marked” but for some reason your code is not affecting that line and not translating it. See screenshot: https://jmp.sh/a4hAGqvz
December 9, 2022 at 1:06 am #2455531Fernando Customer Support
I see. If it’s not translating, you may need to submit a translation here: https://translate.wordpress.org/projects/wp-themes/generatepress/
Or, you may need to use a translation plugin.
Those texts are from WordPress, and aren’t controlled by GeneratePress. I can’t see a specific filter to alter their text as well.
-
AuthorPosts
- You must be logged in to reply to this topic.