Site logo

Archived topic

Translate Pagination

7 replies · Started by _blank on November 10, 2021

Viewing posts 1–8 of 8

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

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/

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

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');

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 :D

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

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.

Thanks so much Elvin (again)! It's all working perfectly now. :D

Have an awesome week! :)

No problem. Glad you got it sorted. :D

This archived topic is closed to new replies.