How to Make WP-PageNavi Plugin Supports Multi-Language?

Today, my posts in this website reached more than 10 articles. Therefore, there was an “Older entries” link showed-up in the bottom of my front page. Well, I want this link text become pagination link that automatically detects the number of the page. So I searched, found, and used WP-PageNavi plugin for this purpose, and everything seemed okay so far until I found a little bit problem. This plugin has not fully supported multi-language, especially my own language; bahasa Indonesia, yet. When the pagination link showed-up, it bothered me that the Page and of words have not been translated to my language when I choose my language as the selected language. So I decided to modify this plugin’s script. Edited: This following modification being applied for 2.73 (the last version when I edited this article). I have sent the .mo and .po files to the author in order to be included into the next release.

  1. Open core.php file, and find this code:

    60
    61
    62
    63
    
    				$pages_text = str_replace(
    					array( "%CURRENT_PAGE%", "%TOTAL_PAGES%" ),
    					array( number_format_i18n( $paged ), number_format_i18n( $total_pages ) ),
    				$options['pages_text'] );

    then replace it with this following code:

    60
    61
    62
    63
    
    				$pages_text = str_replace(
    					array( "%CURRENT_PAGE%", "%TOTAL_PAGES%" ),
    					array( number_format_i18n( $paged ), number_format_i18n( $total_pages ) ),
    				__('Page %CURRENT_PAGE% of %TOTAL_PAGES%','wp-pagenavi') );  // Modified by Masino Sinaga, August 29, 2010 in order to support multi language; old: $options['pages_text']
  2. Find again this code:

    69
    
    				$out .= _wp_pagenavi_single( 1, 'first', $first_text, '%TOTAL_PAGES%' );

    then replace it with this following code:

    69
    
    				$out .= _wp_pagenavi_single( 1, 'first', __($first_text,'wp-pagenavi'), '%TOTAL_PAGES%' ); // Modified by Masino Sinaga, August 29, 2010, in order to support multi language
  3. Find again this code:

    115
    
    				$out .= _wp_pagenavi_single( $total_pages, 'last', $options['last_text'], '%TOTAL_PAGES%' );

    then replace it with this following code:

    115
    
    				$out .= _wp_pagenavi_single( $total_pages, 'last', __($options['last_text'],'wp-pagenavi'), '%TOTAL_PAGES%' ); // Modified by Masino Sinaga, August 29, 2010 in order to support multi language

Now the link has used my language when this language selected. It become: Halaman x dari y.

Share

2,086 viewsPrint This Post Print This Post

Comments

  1. wow so nice the web

  2. Thanks! Yours, too.

  3. Bohdan says:

    Thank You! :)

  4. Oh my Gosh! It’s the very first time that I found code snippets and an explanation that both works! Thank you very much. :)

  5. Katie says:

    This worked perfectly – thank you.

  6. Ignacio R says:

    Incredible. After 2 years of posted it still works !

    Good job !

  7. aban says:

    Makasih bang! It did help!!!

  8. Antonio says:

    I can confirm that it works beautifully on WPML 2.4.2 and WP3.3.1 (line numbers are slighty different, and the function _wp_pagenavi_single is now $instance->get_single). Thank you for the post.

Speak Your Mind

*


*