We're merging with GenerateBlocks! Learn more here.

[Resolved] Ajax “Load More” Translation

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Ajax “Load More” Translation

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #25410
    Yurik
    Participant

    Hi,

    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
    Yurik

    #25436
    elvin
    Moderator

    Hi,

    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.

    #25480
    Yurik
    Participant

    Hi 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

    #25492
    elvin
    Moderator

    I 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/

    #25523
    Yurik
    Participant

    HI 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
    Yurik

    #25605
    elvin
    Moderator

    No problem. Glad you got it sorted. 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.