Home > WordPress > How to Make WP-PageNavi Plugin Supports Multi-Language?

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 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 modified this plugin’s script.

All that I had to do was:

  1. Created a new sub directory named langs under the \wp-plugin\ sub directory.
  2. Opened wp-pagenavi.pot file by using Poedit tools.
  3. Translated it to my language, then save it as: wp-pagenavi-id_ID.po file. You will see that since I used Poedit tools, it would automatically created a wp-pagenavi-id_ID.mo file, too.
  4. I put both files (wp-pagenavi-id_ID.po and wp-pagenavi-id_ID.mo) that I saved in the third step above to langs sub directory.
  5. Open wp-pagenavi.php file and edit this code:
  6. 33
    34
    35
    
    function pagenavi_textdomain() {
    	load_plugin_textdomain('wp-pagenavi', false, 'wp-pagenavi');
    }

    replace with:

    33
    34
    35
    36
    
    function pagenavi_textdomain() {
       load_plugin_textdomain('wp-pagenavi', PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)) . '/langs/', //2.5 Compatibility
    	dirname(plugin_basename(__FILE__)) . '/langs/'); //2.6+, Works with custom wp-content dirs.
    }

    Find this code:

    113
    
    $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options['pages_text']);

    replace with with:

    113
    
    $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), __('Page %CURRENT_PAGE% of %TOTAL_PAGES%','wp-pagenavi'));
  7. Save the file.

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

  • Share/Bookmark
617 views Print This Post Print This Post

  1. July 2nd, 2010 at 06:11 | #1

    wow so nice the web

  2. July 10th, 2010 at 23:58 | #2

    Thanks! Yours, too.

  1. No trackbacks yet.