How to Translate a WordPress Plugin in Any Language

How to Translate a WordPress Plugin in Any Language

Adam Morgan

Capturing the hearts and minds of a much larger, international audience may require the translation of WordPress plugins. Thankfully, there’s an easy way to go about doing this. It won’t require the use of a professional translator and you’ll be able to automatise the process for use in any language.

Finding the right plugin

Some plugins are more favourable for translation than others. In order to save yourself time and expense, it’s essential to find the plugins which are translation ready. In other words, those with code localised across the GNU gettext framework. If it’s not made apparent on the list of Plugin features, you can always contact the developer directly to make sure it’s been localised.

Choose a translation tool

There is a great choice of tools designed to translate WordPress Plugins. These include Launchpad, Pootle, GlotPress and arguably the most popular, Poedit. It’s a free and easy to use program which enables editing of PO files, as well as the generation of MO files. In this example, we’ll guide you through a translation using the Poedit interface.

Let’s begin

After installing and launching Poedit, click on ‘File’ followed by ‘New catalog from POT file.’ A properties box will open which requests information on the content that needs translating. Here you can enter the translation language required followed by other specific details.

Once you’ve clicked ‘ok’ you’ll have the option to name the file. This shouldn’t be overlooked as the name should be consistent with the language you are translating to. The file name should show both the language and country code. These can be found on the GNU gettext utilities. For example, if you’re translating to Spanish for Spain, the name would be ‘mp-sp_SP.po’. Mp stands for MarketPress plugin followed by ‘sp’ for Spanish and ‘SP’ for Spain. Always name files in this way to ensure consistency and avoid errors in the future.

This file should then be saved in the languages folder of the plugin. From here, you can begin the translation process by following the simply navigation of the Poedit interface. The section at the top shows all text to be translated and the right hand side will display all completed translations. After you’ve finished the full translate, be sure to save the file and Poedit will create both .po and .mo files into the language folder.

Setting up the plugin

After compressing the folder and uploading back to WordPress, you’ll be ready to setup the Plugin. Given that English is the default language in WordPress, you’ll have to add code in order for the setup to run smoothly. After opening the wp_config.php file, simply add the following code: ‘define ( ‘WPLANG’ , ‘zh_CN’);’

The ‘zh_CN’ part should be replaced with your language and country code. For example, that would be ‘sp_SP’ for Spanish. This should complete the setup and ensure WordPress now recognises the Plugin in Spanish. This is the language that now shows to users but your backend should still remain in English.