Themes and Mods

Find Wordpress Themes, Plugins, Joomla Templates, Extensions

Best WP Sites

A Definitive Guide on Localizing a WordPress Theme

The continuous surge of WordPress web development has resulted into a sudden hike in the demand for WordPress themes that can be utilized for different types of websites. While a majority of WordPress themes are available in English, lately, more and more WordPress users have been demanding for the translation of a WordPress theme into a language instead of the default English language. Today, through this tutorial, I’ll be sharing with you the method of localizing a WordPress theme. So, let’s get on with our journey of learning more about this handy method.

What’s the exact need for localizing a WordPress theme?

Since WordPress is used across the globe, it is a good idea to prepare the WordPress themes so that they can be conveniently translated into a wide range of other local languages. Localization basically means making a WordPress theme ready for the translator which can further convert it into a different language. Talking about the unique terminology used in the concept of WordPress Theme Localization, I’d like to make you familiar with I18n. This is an abbreviation for the word “Internationalization”. It is called i18n simply because there are 18 letters between “i” and “n”. Next, there is a different term ‘I10n’ which is an abbreviation for the word ‘localization’. Collaboratively, both i18n and I10n represent the basic process of making a WordPress theme ready-for-translation.

Getting to know about the Localization Framework

Firstly, let’s have a look at the files that would be used for localizing a WordPress theme. Well, before that, it is important for you to know that by default, WordPress uses GNU gettext localization framework for translating a WordPress theme. The three types of files used here include the following:

  • POT (Portable Object Template) file: This file would contain all the text that’s available for translating the WordPress theme. As the very first step, we’ll be using a program for searching through WordPress source code for fetching the text that’s passed into a _() or _e() function. Doing this would help us in generating a POT file.
  • PO (Portable Object) files: As per the second step, the text in the above POT file is being translated into the target language, Here, the English and translator messages are being saved into a PO file which is identical to the POT files.
  • MO (Machine Object) files: Finally, the PO file is being converted into a machine readable file format.

Now, moving on to the basic steps associated with localization of a WordPress Theme

Step 1:- Include the load_theme_textdomain function into the WordPress theme’s functions.php file

As per the very first step, just include the below function into your theme’s functions.php file:

load_theme_textdomain( ‘mytheme’, templatepath.’/languages’ );

In the above function, replace ‘mytheme’ with the name of your WordPress theme and ‘templatepath’ with the location within your themes folder where you intend to save the translation files. It is a good idea to crate a ‘Languages’ folder in the theme directory and save your files there itself.

Step 2:- Edit the text strings in your theme files

For editing text strings in the theme files and converting them into easy-to-translate functions, just wrap the same into a _() function call. For instance,

<?php echo ‘
<h2>Hi Guide Team!</h2>
‘; ?>

will become

<?php echo ‘
<h2>’ . __(‘Hi Guide Team!’, ‘themename’) . ‘</h2>
‘; ?>

On the contrary, if the code echoes the string to the chosen browser, then it is recommended to use _e() function as shown below:

<?php echo ‘Hi Guide Team!’; ?>

will become:

<?php _e(‘Hi Guide Team!’, ‘themename’); ?>

Step 3:- Create a POT file

With the theme files ready, you need to create a POT file. This file would be delivered with the theme, allowing the translator to translate the files using Poedit- an open source program designed for Windows, Mac OS X and UNIX/Linux. Have a look at the below steps involved with the creation of a POT file:

1.    Install the Poedit software program

2.    Go to Poedit dashboard and there click on File-> New Catalog

3.    Click on ‘Translations properties’ tab available under the Catalog Properties window. A screen similar to this will be displayed:

wp localization

Here, fill in the details for the project.

4.    Now, go to Sources paths tab. Here, enter the path for folder that would be used by Poedit in order to search for the source files that include the translatable text. For your information, the base path for the ‘Languages’ folder would be “../

5.    Next, click on ‘Sources keywords’ tab where you’ll be expected to define the functions that would be used for localizing the text files in the WordPress theme files viz: _() and _e()

6.    On clicking the ‘Ok’ button, you’ll be expected to enter a suitable name for your POT file, followed by saving it. Do note, by default Poedit would save your file as .po fil, but you can go ahead with saving the file as .pot file. In other words, name your file after the theme’s name, giving it a .pot extension and saving it in the ‘Languages’ folder available in the WordPress themes directory.

7.    Finally, clicking on ‘Ok’ will make Poedit scan all the folders that you’ve specified in the ‘Sources Paths’ tab, followed by listing the localized text within the theme’s files. Lastly, just save your POT file.

With that we’re done with localization of our WordPress theme i.e. making the theme translation-ready.

Conclusion

Here’s hoping the above tutorial would help you in localizing your WordPress theme, the next time you intend to translate it into one of your preferable languages.

Author Bio
Choosing Ava Garcia can serve as the best option if you’re looking ahead to hire WordPress developer for meeting your website development needs. When not busy developing WordPress website, she likes sharing her knowledge about all the recent advancements in the world of WordPress development. Currently employed with OSSMedia, she has a huge collection of helpful WP – related articles published under her name.

Tagged with: ,


Please let us know your comments and suggestions:

Comments are closed.
Note: All the templates and extensions listed in this site are from their respective developers and all support requests should be sent directly to the developers. We do not provide support for any of the templates or extensions listed in this site. We just make some revenue if you purchase any of the product through the link from our site.