How to Translate WordPress Themes

If you are planning to translate WordPress themes, you need to understand the following terms in advance: internationalization (aka i18n) and localization.

translate_wordpress

WordPress localization technology uses GNU gettext localization framework. Gettext allows to display messages using paragraph or single words. In WordPress these messages are generated and translated using two common functions: __() and _e().

Undestanding gettext files

gettext uses the following files:

  • POT (Portable Object Templates) files
  • PO (Portable Object) files
  • MO (Machine Object) files

Translating Themes

In order to translate themes, the follow steps need be achieved:

Choose a translation tool for your environment. In Windows, Mac OS X and Linux  you can use poEdit. Other tools are GNU Gettext, Pootle, Launchpad.

Edit translation files and prepare your WordPress themes.

How to translate my WordPress themes

To translate themes, you need to create a .po file and locate it under your theme directory. The filename should be accordingly your locale. For example, if you are translating a WordPress theme to Spanish in Spain, it would be desired to name it es_ES.po

Go to poEdit (or any other translator tool used) and create that file or open it if already exists.

You need to configure the properties, directories and functions that will be used to determine the potential translation terms. Usually the two functions you need to specify are __() and _e().

On your main screen you will see a list of terms and a secondary pane where you can translate each term to the new language.

Once you finished with the translation, then you need to save it two times. One time for saving the .po file, and other time to save the compiled one, that’s the .mo file.

Tip: poEdit has a configuration option to automatically compile the file when saving so you can just save both files in a single click.

In order to use translation, you need to edit wp-config.php to match your language:


define('WPLANG', 'es_ES');

You can repeat the steps for other languages, in case you also want to provide translation for Portuguese, Chinese, and so on.

Then, your WordPress instance is ready for your new language.

Advertisement

Did you like it?

No comments yet.

Leave a Comment