Translate Plugin Headers in WordPress 2.7

Improvements that just hit the trunk today allow you to add the plugin headers to the .POT file. There are a few ways of getting the plugin headers into the .pot file, where if it is translated will be displayed in the plugin administration in that language. There are two online tools that will pull the plugin header data out and put it into the .pot file.

The first one is part of Automattic i18n Tools and the second is either part of or will be part of the new Plugin Extend Administration interface online translate tool for your plugins to create a .POT file.

New Plugin Headers

The two new plugin headers for allowing translating the plugin header is “Text Domain” and “Domain Path”. The only one that is required is the “Text Domain”, which is the same as text domain that you have in your plugin.

  1. Text Domain – Unique name to identify your plugin from others.

    < ?php
    /*
    Text Domain: mydomain
    */
    
  2. Domain Path – Optional and only needed if the .mo files are stored in a separate file relative to your base plugin directory. If the directory is located relative to wp-content at plugins/my-plugin/lang_folder, then the “Domain Path” would just be lang_folder.

    < ?php
    /*
    Domain Path: lang_folder
    */
    

PHP Hack to Get Plugin Headers in the .POT File

There is a more hackish way that doesn’t rely on the above two to get the plugin headers in to the .POT file.

/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the plugin.
Version: The plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
Text Domain: mydomain
Domain Path: lang_folder
 */

$plugin_header_translate = array(
    __('A brief description of the plugin.', 'mydomain'),
    __('Name Of The Plugin Author', 'mydomain'),
    __('http://URI_Of_The_Plugin_Author', 'mydomain'),
    __('Name Of The Plugin', 'mydomain')
);

A warning about offering the plugin name to be translated, if you do so, then it is possible that the automatic plugin updater will not recognize your plugin and therefore will probably not check for updates.

Translating the name and other parts will have no negative effects on the plugin updater. This was fixed in revision r8368. No word yet on if this will be in 2.6.1, but I’m crossing my fingers. Well, WordPress 2.7 should be out September-ish and 2.6.1 should be out towards the beginning of next month.

Possibly Related Posts:


2 Comments.

  1. Very cool. Will this carry over to themes too?

  2. There will be an external and online tool based on the WordPress Extend for themes that will do this eventually. Support has already been added for plugins, so eventually that will make its way over to themes extend also.

    I’m not real big on i18n, so I’m pretty much done with as far as support on this feature.