Create a .pot or .po File using Poedit
Poedit1 is an extremely popular Gettext2 catalogs editing tool known for its ease of use and fast speed. Numerous WordPress developers and translators are now constantly using this tool to internationalize and localize plugins and themes.
During such internalization and localization processes, a .pot and .po file are created. They are identical in every aspect except for their purposes. A .pot file is often created by the plugin or theme author himself and then delivered along with that plugin or theme so that translators can translate such project using Poedit conveniently. When a translator finishes his job, a .po and a .mo file will be created and will be eventually used by end-users.
After you have downloaded Poedit and installed it, fire the application up and then choose File → New Catalog. You’re now at the ‘Project info’ tab. ‘Project name and version’ should be your plugin’s name, ‘Charset’ and ‘Source code charset’ should be ‘utf-8′. Switch to ‘Paths’ tab and choose to add a new item, as described in the screenshot below:
Type in a dot (.) to tell Poedit to search for PHP files in the same folder as the .pot file. Next switch to ‘Keywords’ tab, press the same ‘New item’ button and add all Gettext functions you use for your plugin, most of the time only
_e are needed. Make sure all necessary functions are added and press OK. Now press File again and save your file in the same folder as your plugin’s main file (i.e. the PHP file that WordPress will use to load your plugin). By default Poedit saves your file as a .po file but since the two files are identical you can get around that by simply choosing to save the .po file as a .pot file:
You can rename the .po file later if you wish. Remember to delete the .mo file created along with our fake .pot file because it is not needed by our translators.
After your .pot file is nicely saved, navigate to Catalog and choose to ‘Update from sources’:
Just sit back and wait for the process to complete. After you press OK the main screen should be filled with strings that need translating from all of your plugin’s PHP files, excellent! The last thing to do is to save the file again and packed it with your project (remember to again delete the .mo file because each time you save the .pot file another .mo file will be created).
Creating a .po file (for translators)
To create a .po file, simply follow these steps3:
- Download and install Poedit if you haven’t done so already.
- Download/request a .pot file or create one yourself if the plugin or theme doesn’t supply such file.
- Open the .pot file in Poedit.
- (See Image on the right) The box labeled (1) is the original message (in English) from the .pot file. The box labeled (2) is where you add your translation. Boxes labeled (3) and (4) are used for adding comments about the messages. These come in handy if you are working with a team of translators and would like to pass around ideas through the .po file.
- Go to File → Save as… to save your translations in a .po file. If you do not know how to name it, take a look at this page: http://codex.wordpress.org/WordPress_in_Your_Language. The name you should use is the combination of the project’s text domain (locate it inside codes) and a short string in parentheses next to a language’s name (e.g. French – Français (fr_FR)). For example, if the text domain is bwp-minify and the translation is French, just name the .po file
- When you have finished translating, go to File → Save as… again to generate the .mo file. Or you can set your Poedit to always compile a .mo file when saving changes by clicking File → Preferences and on the Editor tab check the Automatically compile .mo file on save box.
Updating a .po (and .mo) file
Another task of a translator is to update a .po file whenever a particular project has just been updated with more strings to translate, or even obsolete ones. To update your .po file, again navigate to Catalog, but this time choose ‘Update from POT file’, and then choose the .pot file from which you would like to get updated contents. Next, translate the project as you would normally do and save all changes.
Now that you’ve known how to create a .po file, i.e. translate a plugin, please consider translating my WordPress plugins. Finished translations should be sent through the contact fom or through a direct email to contact (at) betterwp (dot) net. Thanks!
- http://www.poedit.net/index.php [↩]
- http://www.gnu.org/software/gettext/ [↩]
- http://codex.wordpress.org/Translating_WordPress#Transl ... ith_Poedit [↩]