(Reading time: 2 – 4 minutes)
Internationalization for WordPress isn’t difficult, but it can be a bit tricky to get everything all lined up correctly.
This plugin is just a simple, single file, and all it does is add a translation for it’s administration (options) page.
Very, very simple, and anyone should be able to use it for a pattern to internationalize their own WordPress plugins.
Here’s a source listing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <?php /* Plugin Name: Demo Plugin i18n Plugin URI: http://website-in-a-weekend.net/plugins Description: Very concise example of i18n implementation. Version: 0.1 Author: Dave Doolin Author URI: http://website-in-a-weekend.net/plugins */ /* Copyright YEAR PLUGIN_AUTHOR_NAME (email : PLUGIN AUTHOR EMAIL) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ if (!defined('WP_CONTENT_URL')) define('WP_CONTENT_URL', get_option('siteurl').'/wp-content'); // Technique copied from Joost de Valk sociable plugin $dpipluginpath = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)).'/'; if (!class_exists("demo_plugin_i18n")) { class demo_plugin_i18n { function demo_plugin_i18n() { register_activation_hook(__FILE__,array($plugin_class, 'activate_i18n')); add_action('admin_menu', array ( & $this, 'on_admin_menu')); add_action('init', array(&$this,'activate_translations'),10); } // Empty, placeholder function activate_i18n() { } function activate_translations() { global $dpipluginpath; load_plugin_textdomain('dpi', $dpipluginpath.'/lang', 'demo-plugin-i18n/lang'); } function on_admin_menu() { add_options_page(__('Demo i18n Page','dpi'), __('Demo i18n','dpi'), 8, __FILE__ ,array(& $this, 'i18n_options')); } function i18n_options() { global $dpipluginpath; ?> <div class="wrap"> <h2> <?php _e("Let's get on with it!",'dpi') ?> </h2> </div> <?php } } } $wpdpd = new demo_plugin_i18n(); ?> |
More information coming very soon.
[sniplet more-plugins]
Teach yourself plugin programming
The WordPress plugin subsystem is a piece of art… poetry as claimed on wordpress.org.
If you are serious about learning how to program WordPress plugins, run, don’t walk to purchase Vladimir Prelovac’s “WordPress Plugin Development Beginner’s Guide.”
