Translating Your WordPress Theme

In our quest to dominate the world one website at a time we thought it would be a great idea to make it easy to translate your ThemeBeans theme (just another great feature built into the ThemeBeans Framework :)

Before we begin you will need this list of tools

Shortcuts


How a Translation Works


WordPress uses gettext files for translation, here are three types of files used in the gettext translation framework. These files are used and/or generated by translation tools during the translation process, as follows: (you can learn more about this at the WordPress Codex here http://codex.wordpress.org/Translating_WordPress ).

POT (Portable Object Template) files

The first step in the localization process is that a program is used to search through the WordPress source code and pick out every message passed into a __() or _e() function. This list of English-language messages is put into a specially-formatted template file (POT file) that forms the basis of all translations. Generally, you can download a POT file for WordPress, so you shouldn’t have to generate your own. Separate POT files can also be made for themes and plugins, if the theme/plugin developer has enclosed all text in __() or _e() functions.

PO (Portable Object) files

The second step in the localization process is that the translator translates all the messages from the POT file into the target language, and saves both English and translated messages in a PO file.

MO (Machine Object) files

The final step in the localization process is that the PO file is run through a program that turns it into an optimized machine-readable binary file (MO file). Compiling the translations to machine code makes the localized program much faster in retrieving the translations while it is running.

That’s the technical side of things from WordPress, but you don’t need to worry about this to much as we have taken care of things for you


Download a Translation Ready Theme


WordPress Theme

Head over to this page and grab one of our great themes https://themebeans.com/themes/ you can click on a theme and then view a live demo of each one, when you have decided which theme is perfect for you click on the Purchase Theme link and you will be redirected to out ThemeForest page


Using Poedit


Install and open Poedit, then click on File → New → New From POT / PO File

po-file

Then open the en.po file that is located in the languages folder within your theme (if it does not show up straight away make sure you are trying to open a .po file-type and not the .pot file-type).

filetype

This will then take us to the next option to choose the translation that we are about to create ( you can view the list of language names here http://www.gnu.org/software/gettext/manual/gettext.html#Language-Codes ). How we name the file is very important as WordPress will only recognize a particular format, if you are doing a French translation then the file name will be fr_FR and for Polish it would be pl_PL.


Creating Your Translation


Once we have the en.po file open from your theme you will see the list of source text that is ready for translation, so you click on the source text that you want to translate and add your translation into the Translation box. Keep going through the file until all translations are complete then save your file into the languages folder in your theme ensuring you are saving with the correct file name, in my example I am saving as fr_FR.po

source-text

save


Telling WordPress That The Theme Has a Translation


We are nearly done, its as simple as that! We have one last step to let your WordPress know that your theme has a translated file and you want to use this for the front end, you need to open your wp-config file located in the root of your WordPress set up and then scroll down until you find

	define('WPLANG', '');

This is where we set the language for the file that we have just created so in my case I change this to

	define('WPLANG', 'fr_FR');

Then don’t forget to save your changes.

config

Just to make sure that this has worked go to the live site and check that the translations are showing up correctly.

translated


Other ways in which you can use this method to customize a site


We could use this feature and manipulate it to customize a site to a clients needs, you may be creating a site for a local band and want to change some of the wording is certain elements of the site, for instance you may want to change the string “Comments” to “This is What Our Fans Say”. With a little thought about the various sections of the site you can really make your ThemeBeans site very unique ;)

fans

And The Result

comments


Other Translation Tutorials We Will Cover Soon


  • How to Translate The WordPress Dashboard
  • Making Your Site Multilingual
For more updates, follow @themebeans and @richard_tabor on Twitter.

Archive