How to Translate a WordPress Theme?

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 translation-ready theme means that the theme developer didn’t hardcode the text strings visible to the user. Instead, he wrote them in a way they become recognizable by WordPress and they can dynamically change to their corresponding translations when a non-English language is chosen.

Making a theme translation ready is the theme developer’s responsibility but you still need to choose a translation-ready theme if you want to offer your site in a language other than English.

How it Works?

WordPress uses the GNU gettext localization framework for translation which involves the use of 3 types 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 searches through the theme source code and logs the text passed into a __() function (& other 3 functions).
  • PO (Portable Object) files: These files contains the same strings that have already been logged in the template file alongside their corresponding translations.
  • MO (Machine Object) files: These files are machine-readable and generated from the PO files.
The easiest way to check if a theme is a translation ready is to look for .pot file inside the theme folder. Most developers put these files in a “language” or “lang” folder. If you find that file, then your theme is ready to translate.

How to Translate a WordPress Theme?

There are multiple ways to translate a WordPress theme. Either by using a plugin like WPML or Polylang, or by generating the translation files yourself using software or an online tool.

Using WPML

If you are using WPML to offer your site in multiple languages, you can easily translate your theme to multiple languages directly from WPML. You can follow this guide on WPML website to learn how to do it.

Using Poedit

If you choose to translate the theme yourself, I recommend using Poedit for the job.

Poedit is a freemium and open-source program available for Windows, Mac OS X, and Linux that will make translating WordPress themes a piece of cake!

Step 1. Download and install Poedit.

Step 2. 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 a sub-folder named “lang” or “languages”.

Step 3. Now a Translation Language box will pop up asking for the language of translation. Select the language and click OK.

Step 4. 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 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 a few of them. This is totally up to you!

When you’ve finished 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

The translation files are applied automatically when you change your WordPress language if the theme has been already translated to that particular language.

However, if your theme still appears in the default language it comes with (usually English) we can force applying the translation files using a quick trick.

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', 'fr_FR');

Remember to change “fr_FR” to the name of your PO file.

[alert type=”warning”]Note this will not change the WordPress backend language. It will only change your theme language.[/alert]

Please be aware that both .po and .mo files must be named in a particular format. For example, if you’re translating to Arabic, the files should be named ar.po & ar.mo, and for French translation for France, the files should be named fr_FR.po & fr_FR.mo.