How to translate my WordPress theme in a child theme? [Quick Guide]

6:10 pm May 15, 20178945

Translate my child theme can be complex… Yet, you have seen lately on WP training it was very easy to translate the theme using the extension Loco Translate … However, if you prefer not to be dependent on a plugin, there is another solution: translated my WordPress theme in a child theme with Poedit . Let’s look at the steps to achieve this…

Traduire son thème enfant

Step 1: prepare the environment necessary to translate my child theme

one of the solutions, not suitable, would be to create a file for translation directly in your parent theme… The concern would be that your translation would disappear in the next updated theme! Going therefore, beforehand, create a child theme. If you don’t already have one, you can read article which will help you to create easily.

Then, you will need the Poedit software which offers a free version that will be sufficient to make the changes you need. This software is available for Mac and PC on the official website . Download it, then install it on your computer.

Step 2: retrieve the .po file available in your theme parent

Dupliquer le fichier po en local

in order to create your translation, you will need the file .po to your parent theme. You are sure to find in the folder languages or lang theme. It could appear under the name of en_EN.po or even xx_XX.po if the theme developers have planned this. Once the file for been spotted, save a copy in your local environment on your desktop for example.

Step 3: create a new translation with Poedit file

as your environment is ready, you can start your translation. A few steps will be enough to get your new file fr_FR.po, , however, if you want to translate your theme in a language other than the french, see to documentation for the official code of the desired language:

Créer une nouvelle traduction avec Poedit

  1. open Poedit and then click on “create a new translation”
  2. a popup will open and allow you to select the file that you just saved locally (cf (: step 2), the famous en_EN.po , then click on “open”
  3. Poedit will ask you to set the language of this new translation, select “french” and then click “accept”.

Step 4: start translation with Poedit

Traduire le theme

translation can begin: the translation strings available (in blue) located on the left of your screen and on the right are the translations that you make (in green). It’s at the bottom of the screen you can enter your translation (in the green box).

Attention! Be sure to keep all of the special characters that are useful to your theme in your translation such as “ % ” or “ %s ” for example.

Translate all strings you need, knowing that some of them correspond to only available side translations administration while others are those that the user sees when he visits your site. You are therefore not required to translate the entirety of your theme, however, if that’s what you want to, you can check the status of your translation all at the bottom of Poedit (red arrow in the screenshot) which will tell you the percentage of translation already made.

Step 5: build the new .po and .mo files

Générer les fichier po et mo

once you have performed all the translations required for your theme, you can finish by the generation of new .po and .mo files:

  1. always in Poedit, go to file > save
  2. a popup opens and allows you to enter your file name for the french-online en_US (without “.po” or “.mo”)
  3. choose your location and then finish by “Save”
  4. the Poedit software generates then two files: fr_FR.po and fr_FR.mo
  5. these two files are required and you will need to send in your child theme via FTP. You can also store them in a subfolder that you would name “lang” or good “languages”

Importer le dossier langue dans le thème enfant

step 6: modify the file functions.php to your child theme

Ajouter une fonction au fichier functions.php

If you stop at step 5, you will see that translation sent in your child theme for not been taken into account! Indeed, so that it is, we have to add a function to the file functions.php to your child theme, only two enrolled in red parameters to customize according to your theme:

 / / consideration of the issue of translation of the child theme instead of the parent function my_child_theme_setup() {load_child_theme_textdomain ('  text-domain-du-theme-parent ')} get_stylesheet_directory(). (' /languages '); languages being the path of the folder in which your .po and .mo files are} add_action ('after_setup_theme', 'my_child_theme_setup'); 

The function “load_child_theme_textdomain” requires as the first parameter in the “text domain” of your parent theme (required), you will have to customize this setting based on the theme you are using. If you want more information on this function, you can visit the dedicated page on the Codex de WordPress .

Where to find the Text Domain of the topic parent to translate my child theme?

Localiser le Text Domain du thèeme parent

in General, the text domain of the parent theme is easily localizable in header file style.css of it and it is often the same name as that of the template…

However some themes can give you of trouble if the developers have not registered this information in header and do not use the same name as that of the template (this is the case of SimpleMag with which I performed this test)!

Therefore search in the file functions.php theme the function named parent “load_theme_textdomain” . The first parameter located in parenthesis will tell you the name of the text domain which will be useful for translated my child theme ! In my example, it’s “themetext” (nothing to do with SimpleMag!)

Step 7: check the

Vérifier l'état de la traduction

in conclusion, if you have followed these steps, you should get the result and see your translations on the side of the front end… If you spot a few translations forgotten, repeat steps 4 and 5.

in conclusion…

There is no better solution between using a plugin like Loco Translate or translating the theme manually with Poedit. In my opinion, it’s a question of affinity…

But what is most important with the Poedit method, it is translated my child theme rather than its topic parent to keep changes in a future update.