softsprint menu Order

Translation of WordPress themes: _e function and .mo, .po files

December 5, 2016 in 12:56 pm | wiki

This article is dedicated to the translation of WordPress themes without having to connect plugins like qTranslate X.

Quick algorithm is as follows:

1) PHP files have to use this type of function (for example h1 tag):

<h1><?php _e('title', 'softsprint'); ?></h1>

‘title’ – this is the text that we aim to translate. It will appear in the tag h1 of our theme.
‘softsprint’ – the name of the theme folder which has to be translated. In our case, the folder is named ‘softsprint’.
More about _e function can be read here:

2) Pulling the values for the translation from the PHP files using the online services like and then getting .po file

3) Open the created .po file in Poedit and define the translations for each value. There you have also to define the locale: for example, ru_RU:

4) Save our .po file and compile it into a .mo file. Compiled .mo file has to be renamed into (according to our language).
The list of languages and countries:

5) Put file to the languages, folder in our theme folder (in our case – softsprint). It is not necessary to place .po file in the folder, but save it for yourself – possibly you will need to edit / add new translations in the future;

6) Add the next code in the functions.php file (located in our theme folder):

<?php function my_theme_setup(){
	load_theme_textdomain('softsprint', get_template_directory() . '/languages');
add_action('after_setup_theme', 'my_theme_setup');?>

‘softsprint’ – the name of our theme folder;
‘/languages’ – the folder where the file was placed.

More details about the function load_theme_textdomain are described here:
The result is a concise code in the PHP files without extra plugins (eg, qTranslate X) and constructions of such kind:

<li><?php _e('Google Analytics и счётчики'); ?></li>

In addition, the translation editing is centralized (with a .po file) and does not need to open and edit every php file separately.

Let`s discuss

softsprint heart

Our contacts

Lviv, Ukraine
моб: +380 97 551 44 55

Say hello!