If you’ve developed a useful plugin for WordPress, that’s great – but it’s even better if you make your plugin accessible to users speaking other languages.
The good news is that you can easily make your plugin translation ready. That way it will be available in several different languages.
However, there’s a detail which is not always translated by plugin developers: the description of a plugin. In this quick tip, I will cover how you can translate this description.
Allowing People to Translate Your Plugin’s Description
To make your plugin translation ready, you generate a POT-file. This file contains all the strings you use in your plugin. To translate your plugin in a given language, one can create a PO-file from this a POT-file and then translate each string, one by one.
By default, the POT-file does not only contain the strings you use with specific functions like
_e() it contains three additional strings: the name of the plugin, the URL of the plugin’s website, and the description of the plugin.
That means that, by default, contributors can translate this information. There is a problem – these translations are not used unless you indicate to WordPress that they exist.
To do that, go back to the comment that describes your plugin to WordPress. Located in the main file of your plugin, this comment is mandatory and is used by WordPress to know the name of your plugin and other useful information.
In this comment, there are several required pieces of information to provide, but there are also some optional things you can choose to add. In this list of optional information, we find the text domain used by your plugin to be localized, and the path to the folder containing the localization files.
The comment is a list of key / value associations. For example, below is the comment used by previous versions of my plugin WP Photo Sphere.
<?php /* Plugin Name: WP Photo Sphere Plugin URI: http://jeremyheleine.me Description: A filter that displays 360×180 degree panoramas. Please read the readme file for instructions. Version: 2.0 Author: Jérémy Heleine Author URI: http://jeremyheleine.me License: MIT */ ?>
The POT file generated for these versions contains the description. However, as there was no mention to the text domain used by WP Photo Sphere in the comment, the translations of the description weren’t used.
Below is a more recent comment I used since there are several versions.
<?php /* Plugin Name: WP Photo Sphere Plugin URI: http://jeremyheleine.me Description: A filter that displays 360×180 degree panoramas. Please read the readme file for instructions. Version: 3.6.2 Author: Jérémy Heleine Author URI: http://jeremyheleine.me Text Domain: wp-photo-sphere Domain Path: /lang/ License: MIT */ ?>
Two new entries can be seen here:
Text Domain and
Domain Path. The value to indicate in
Text Domain is the text domain used by your plugin, the one you load in your plugin with
Domain Path entry must be filled with a path. In this entry, the root is your plugin’s folder. You have to indicate a subdirectory of this folder, the one that contains all the needed MO-files.
If you use these entries, and if translations for the plugin’s description are available in the current language, these translations will be used. If you want, translations for the plugin’s name can also be used (just don’t remove the corresponding entry in the POT-file!). As said above, the plugin’s URL can also be translated. It can be useful if you provide this webpage in several languages, with a parameter in the URL. For instance, you can indicate
http://myplugin.com as the default URL for your plugin, and
http://myplugin.com/fr as the URL for French users.
WordPress provides all the tools you need to translate your whole plugin, even its name or description. However, as the
Text Domain and
Domain Path are not required in the plugin’s header comment, they are often forgotten by developers.
Now you can translate the description of your plugin and describe to all users around the world what it does and why it is wonderful!