[Resolved] Translate Pagination

Home Forums Support [Resolved] Translate Pagination

Home Forums Support Translate Pagination

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1999584
    _blank

    Hello GP support! Thank you so much for such a wonderful theme. πŸ™‚

    I have an English & Japanese multilingual site using Polylang. Although, I noticed the Pagination (Next and Previous) are not translated in Japanese. Is there a way to translate this?

    Many thanks, πŸ™‚
    Daniel

    #1999621
    Elvin
    Staff
    Customer Support

    Hi Dan,

    I’m not sure we can translate the numbers but we can definitely translate the next and previous text for archive pages.

    You’ll need to filter it like this:

    add_filter( 'gettext', function( $text ) {
        if ( '%s Previous' === $text ) {
            $text = '%s 前';
        }
    
        if ( 'Next %s' === $text ) {
            $text = '欑 %s';
        }
    
        return $text;
    }, 10 ,1 );

    change the characters to the correct Japanese characters of preference.

    Here’s how to add PHP – https://docs.generatepress.com/article/adding-php/

    #2000932
    _blank

    Hi Elvin!

    Thank you so much that worked out perfectly! πŸ™‚

    I also noticed that /page is also showing in the URL when selecting a page number from the pagination and /category when selecting from category. Would it also be possible to translate these?

    Thanks,
    Dan

    #2000939
    Elvin
    Staff
    Customer Support

    That’s something not within the theme’s control, unfortunately.

    You’ll need to do a rewrite of the pagination_base for the url.

    Example:

    function change_pagination_base_to_katakana() {
    	global $wp_rewrite;
    	
    	$wp_rewrite->pagination_base = 'γƒšγƒΌγ‚Έ';
    }
    add_action('init', 'change_pagination_base_to_katakana');
    #2001001
    _blank

    Thanks for that Elvin! It looks like rewriting the pagination_base for the URL is creating missing page errors – so I might leave that for now πŸ˜€

    I did notice that the first filter you provided to translate the next and previous text for archive pages works great, although it has also translated onto the English site as well. Is there any way to correct this?

    Thanks again, πŸ™‚
    Dan

    #2001007
    Elvin
    Staff
    Customer Support

    Thanks for that Elvin! It looks like rewriting the pagination_base for the URL is creating missing page errors – so I might leave that for now πŸ˜€

    you need to edit your site’s .htaccess file as well. (this is accessed on FTP. or install a plugin for editing it)

    .htaccess edit context here – https://wordpress.stackexchange.com/a/57090

    As for the filter:

    I’m not sure what locale code Japan uses for Polylang but try this:

    add_filter( 'gettext', function( $text ) {
    if(pll_current_language() == 'ja'){
        if ( '%s Previous' === $text ) {
            $text = '%s 前';
        }
    
        if ( 'Next %s' === $text ) {
            $text = '欑 %s';
        }
    }
        return $text;
    }, 10 ,1 );

    But I’m not sure if 'ja' or 'jp' is the correct locale code for Japan as far as Polylang is concerned. You may have to ask them for this.

    #2004296
    _blank

    Thanks so much Elvin (again)! It’s all working perfectly now. πŸ˜€

    Have an awesome week! πŸ™‚

    #2004308
    Elvin
    Staff
    Customer Support

    No problem. Glad you got it sorted. πŸ˜€

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