Home › Forums › Pro Support › Ajax “Load More” Translation
Tagged: Ajax Load More
- This topic has 5 replies, 2 voices, and was last updated 2 years, 10 months ago by
elvin.
-
AuthorPosts
-
January 13, 2021 at 7:38 am #25410
Yurik
ParticipantHi,
I have a question regarding Translation for “Load More” button (Ajax pagination). English to Russian
I have managed to translate it in wp-show-posts-pro/modules/ajax-pagination/ajax-pagination.php
ajaxurl' => admin_url( 'admin-ajax.php' ), 'more' => apply_filters( 'wpsp_ajax_load_more', __( 'Показать еще', 'wp-show-posts-pro' ) ), 'loading' => apply_filters( 'wpsp_ajax_loading', __( 'Загрузка...', 'wp-show-posts-pro' ) ),
But…. When it live on web, from scratch it appears as NOT translated (English), however, after first click on “Load more” button, the ajax “Loading” starting and the the funtion ‘loading’ => apply_filters( ‘wpsp_ajax_loading’, __( ‘Загрузка…’, ‘wp-show-posts-pro’ ) ), translate the word “Loading” to Russian (‘Загрузка…’). Also, after the next girds are loaded, the funtion ‘more’ => apply_filters( ‘wpsp_ajax_load_more’, __( ‘Показать еще’, ‘wp-show-posts-pro’ ) ), works with correct translation (all next clicks appears as translated). If I do reload the page – the “Load More” appears again en English.
Here is the quick video of how it works on my site: VIDEO
Here is the site
Please can you advise if there is any chance to get the required language appears from start?
Many thanks
YurikJanuary 13, 2021 at 7:31 pm #25436elvin
ModeratorHi,
Go to line 38 and look for this code:
echo apply_filters( 'wpsp_ajax_pagination_button_output', sprintf( '<div class="wpsp-load-more"> <a class="%1$s" data-link="%2$s" data-page="%3$s" data-pages="%4$s" href="#"> %5$s </a> </div>', $button_class, esc_url( $next_page_url ), $paged, $max_page, apply_filters( 'wpsp_ajax_load_more', __( 'Load more', 'wp-show-posts-pro' ), $settings ) ), $settings ); }
You probably missed the
apply_filters( 'wpsp_ajax_load_more', __( 'Load more', 'wp-show-posts-pro' ), $settings )
on Line 50.Although, if I may suggest, instead of editing the plugin, you should just use the gettext or the
wpsp_ajax_load_more
filter to change the displayed language.Example:
add_filter( 'gettext', function( $text ) { if ( 'Load more' === $text ) { return 'Показать еще'; } if ( 'Loading...' === $text ) { return 'Показать еще'; } return $text; } );
This is better because this will still be retained when the plugin updates while the changes you’ve directly applied to the plugin files will be wiped on update.
Another alternative is you can just add this.
add_filter( 'wpsp_ajax_load_more', __( 'Показать еще', 'wp-show-posts-pro' ) ); add_filter( 'wpsp_ajax_loading', __( 'Загрузка...', 'wp-show-posts-pro' ) );
Like the first alternative, this is better because this will still be retained when the plugin updates.
January 14, 2021 at 9:19 am #25480Yurik
ParticipantHi Elvin! Thanks again for your quick and useful reply!
I have followed your suggestion and used the code you’ve provided adding from line 56 and works perfectly for both desktop and mobile:
add_filter( 'gettext', function( $text ) { if ( 'Load more' === $text ) { return 'Показать еще'; } if ( 'Loading...' === $text ) { return 'Загрузка...'; } return $text; } );
I hope that I have used the correct location for this code? If not please reconfirm.
Many thanks and Bets Regards
January 14, 2021 at 8:15 pm #25492elvin
ModeratorI have followed your suggestion and used the code you’ve provided adding from line 56 and works perfectly for both desktop and mobile:
If you’re pertaining to the plugin files. I recommend reverting the files to its default.
Doing the
gettext
filter should be enough to change the read more text language. There’s no need to edit the plugin file’s coding for this.The gettext filter can be placed inside a child theme’s functions.php or a Code Snippets plugin as mentioned on one of our documentations:
https://docs.generatepress.com/article/adding-php/January 15, 2021 at 6:39 am #25523Yurik
ParticipantHI Elvin,
Thank you for advice and recommendation! I have followed your instruction and reverted the plugin file to default.
I have used the Code Snippets plugin as mentioned and added the same “add_filter( ‘gettext’….)” code, the same as you’ve mentioned initially.At the moment it works perfectly.
Many thanks for your support and good recommendations!
Kind Regards
YurikJanuary 17, 2021 at 10:20 pm #25605elvin
ModeratorNo problem. Glad you got it sorted. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.