06 Feb How to Translate a WordPress Theme
If you wanted to add another language to your site, you may have wondered how to translate a WordPress theme. There are a few ways that one can accomplish this. One of the easiest, however, is to use particular themes that have been localized using the GNU Gettext framework. This framework uses 3 types of files to aid in the translation. These are POT, PO and MO files.
If you are reading this article in another language than English, it has been automatically translated by our WordPress Multilingual Plugin.
POT (Portable Object Template) files contain all of the text that has been extracted from your site via Gettext. This is the template that the translators will use to translate your content. PO (Portable Object) files contain the translations along with the original text. Your translators will send this back to you. You will have a different PO file for each language that you have translated. Finally, once you have the PO files, you will compile them into binary MO (Machine Object) files. These are the files that your server will use to show the translations.
Steps taken to translate a WordPress Theme
Confirm whether your theme is translation ready. This can usually be determined by choosing filtering only the themes that are. Go to the feature filter in WordPress and check “translation ready”. If your theme is translation ready, it should have it’s own POT file. If it is not translation ready, then you will have to generate your own POT file using the xgettext utility as part of the gettext framework (more on this below)
You will send this file to your translator to get it localized into your chosen languages.
Your translator will download and install Poedit. This program allows for easy translation of the text. The translator will save a separate PO file with the name of the target language. This will usually be the website’s text domain followed by the language and country identifier (i.e., de_DE.po for German or en_UK.po for UK English)
When the translator saves the file, Poedit will separately compile a MO file. This contains the same information as the PO file but is in a binary format. These are the files that your web server will use to translate a WordPress theme and output the translations.
Open your wp-config file and define the global WPLANG with your abbreviated version of the translation. For example, a German translation would be:
define ('WPLANG', 'de_DE')
Finally, save the MO and PO files in your language folder within your themes directory.
Generating a POT file with Poedit
If the theme that you have selected does not have it’s own POT file, you will have to generate one. This can also be helpful for theme developers who want to make their themes localization ready. Please note, this assumes that the theme was developed with the gettext framework in mind.
Steps to creating a .POT file with Poedit
- Open Poedit
- Select “File” and then “New”
- Choose the language that your theme was designed in (English in this case)
- Select “File”, “Catalogs Manager”
- Create a new project. Use the name of the main folder the theme is saved in
- Select “browse” and find the directory of the main folder where your theme is saved
- Click OK and close the Catalogs Manager
- Select “Catalog”, “Properties”
- Create a new project name, in this case the theme name
- Select the “UTF-8” as the source code Charset. This is set as the default and is recommended
- Select “OK”
- Choose to save as a POT file. This is the language identifier followed by .pot. In this case, it is “en.pot”. Make certain that you end the file name with the .pot designation as the default file type is .po
- Save in the same directory as the theme. Note that you will also have saved a .mo file as well when doing this which you may safely delete
- Go back to “Catalog”, “properties” and select the “Sources paths”
- The base path should be the directory where the theme is saved
- In “paths” select to add a new path. Use the folder where your theme is located and it will place a “.” within the paths section. This instructs Poedit to scan the theme directory and it’s sub-directories.
- Go to the “Sources keywords” tab and select to enter additional keywords
- Here, enter your list of keywords. Usually only __ and _e will suffice. These are the functions where all of the text strings are stored ready for translation
- Close the catalogs manager by clicking “OK”
- Click the “Update” button in your project window.
- Save the project once more
- You are done!
Now that you have your POT file, you can send it to your desired translators and repeat the steps you 2 to 6 in the previous section to translate a WordPress theme.Other posts you might enjoy: