Localization of WordPress Theme – Part I

Web market is increasingly global nowadays. So, offering your theme in different languages can be advantageous to gain theme market share. If you plan to distribute themes or plugins, localizing your code increases your number of potential customers.

Localization is the way of translating your theme or plugin for use in different locales and languages. So, we will discuss more about how to make translation ready theme or plugin.

WordPress uses the gettext translation system developed for GNU translation. The gettext system inside of WordPress includes the following components:

  • Process to define a locale
  • Process to translate strings
  • Three files .pot, .po and .mo
  • .pot file contains all of words and phrases that needs to be translated
  • .po file for each locale contains translations
  • .mo file for each locale contains compiled version of .po

WordPress needs to know way to locate your localization files. This is done by function load_theme_textdomain().

load_theme_textdomain() accepts two parameters: domain of your theme and path to language files.

In the above example, translation files are inside lang folder inside theme folder.

Similarly, for plugin, you need to use load_plugin_textdomain(). You can check details on this link: https://codex.wordpress.org/Function_Reference/load_plugin_textdomain

In next post, we will discuss about different helper functions that WordPress provides for translating words and phrases.