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:
- Created a new sub directory named langs under the \wp-plugin\ sub directory.
- Opened wp-pagenavi.pot file by using Poedit tools.
- 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.
- 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.
- Open wp-pagenavi.php file and edit this code:
- Save the file.
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')); |
Now the link has used my language when this language selected. It become: Halaman x dari y.
Print This Post
wow so nice the web
Thanks! Yours, too.