Translating a WordPress theme in your language is an easy task and does not require any coding or programming skills as long as the theme you are about to translate is Translation ready. A translations ready theme means that the theme creator has implemented some sort of coding to make all the theme hard-coded text (such as the 404 error message) and labels (such as “About the author:” & “Continue reading”) so they dynamically change to their corresponding translations when a non-English language is choosed. Making a theme translation ready (also called Internationalization and abbreviated as
i18n) is the theme developer work so you don’t have to worry about this before trying to translate any WordPress theme, please make sure it’s advertised as translation ready.
How It Works:
WordPress uses the GNU gettext localization framework for translation which involves the use of 3 type of files:
- POT (Portable Object Template) files: These are the template files for PO files (Microsoft’s PowerPoint template files are also using the .pot extension, but they are not the same). Generally, these files are generated by a tool that search through the theme source code and log the text passed into a __() function (& other 3 functions).
- PO (Portable Object) files: These files contains the same strings that has already been logged in the template file alongside their corresponding translations.
- MO (Machine Object) files: These files are machine readable generated from the PO files.
Translating WordPress theme using Poedit:
There is more than one way to translate a WordPress theme. For the sake of this tutorial, we are going to use Poedit; an open source program available for Windows, Mac OS X and Linux that will make translating WordPress themes a piece of cake!
- Download and install Poedit.
- When installed, open Poedit and click Create new translation and select your theme POT file. As I already said, your theme .pot file should be available somewhere in your theme folder. Most developers place this file in sub-folder named “lang” or “languages” .
- Now a Translation Language box will popup asking for the language of translation. Select the language and click OK.
- Now you can start translating your theme. Poedit has a very intuitive and user friendly interface. The Source text field will show the currently selected string. To translate this string, put the cursor inside the Translation field and type the translation. Poedit will try to help you and suggest you human translations for the selected string. Please note that the free version of Poedit will only show you 10 suggestions which will reset each time you close Poedit.
- Every string you translate will be saved in a database and each time Poedit detects this string, it will show you your old translation as a suggestion. You are free to translate all the strings or only few of them. This is totally up to you!
- When you’ve finishing translating, simply Save the file. Poedit will automatically create both .po and .mo files in the same folder where the POT file is placed.
Now that your theme has been translated, you are ready to apply the translation!
Applying your translation:
To change your theme language, simply open wp-config.php file (located in your main WordPress installation folder) with any code editor and add this line at the bottom of the file:
define ('WPLANG', 'ar');
Remember to change “ar” to the name of your PO file.
Note this will not change the WordPress backend language. It will only change your theme language. If you change the backend language from the WP General Settings page and your current theme support this language, it will be applied to the theme too without the need to edit the wp-config.php file, automatically!