Localizing Plugins and Themes

Currently, plugins and themes cannot be localized because their strings are not in the default WP catalog. To remedy this, I added the ability for plugins and themes to load their own catalogs.

To localize a plugin, call load_plugin_textdomain() at the top of your plugin, passing it a string to identify the domain.

load_plugin_textdomain('myplugin');

load_plugin_textdomain() looks in the plugin directory for a file called $domain-$locale.mo where $domain is the textdomain specified in the call to load_plugin_textdomain() and $locale is the language and country code specified in WPLANG. If WPLANG is en_AU and the domain is “myplugin”, the file loaded is wp-content/plugins/myplugin-en_AU.mo.

Now, when you markup strings in your plugin, you must specify the domain in the calls to __() and _e().

__('String to translate.', 'myplugin');

With all strings marked in this manner, your plugin is ready for localization. You just need to generate a POT file and give it to translators.

Theme catalogs are loaded with load_theme_textdomain(). load_theme_textdomain() looks in the active theme directory for a file called $locale.mo. Strings are marked in the same way that plugin strings are marked.

In summary, load_plugin_textdomain() and load_theme_textdomain() load translation catalogs for plugins and themes, respectively. __() and _e() now take a second argument which specifies the catalog in which to lookup strings. You must specify a domain when loading catalogs and marking strings for plugins and themes.

I’ll start localizing the Kubrick theme for 1.3 sometime soon. Mustering the motivation to start such a tedious task is difficult.