Internationalize WordPress: The Basics

Music for the masses

WordPress® is used on a sizable percentage of the world’s websites. As such, WordPress theme developers need to think about how their themes will be used when installed on sites that are in multiple languages. Planning for internationalization and localization (“I18n” and “L10n” for those in the know) is a best practice.

Internationalization vs. localization

While the two terms are often used in the same conversation, there is a subtle difference between internationalization and localization. Internationalization is the process of designing your theme so that it can support various languages without significant engineering changes. It’s setting up the engineering foundation to enable localization.

In contrast, localization is the process of actually translating the appropriate sections of that theme to support a particular language (i.e. Spanish or German).

Conjunction junction, what’s your (translation) function?

Within WordPress, there are a number of special PHP functions that you’ll see a lot when doing I18n and L10n. These most frequently used functions of this type are __() and _e().

The double-underscore function instructs WordPress to return a localized version of a string for a particular text domain. It looks like this:

$name = __( 'Menu', 'my-demo' );

The underscore-e function instructs WordPress to echo a localized version of a string for a particular text domain. It looks like this:

_e( 'Menu', 'my-demo'');

These functions will output the correctly translated version of the given string (in this case, “Menu”) for a given domain.

Where do the translations come from?

WordPress uses a series of files called the POT, PO and MO files to house the translated strings that the translation functions will use.

  • POT (Portable Object Template) files are template files that contain all of the original, English strings to be translated.
  • PO (Portable Object) files are structurally similar to the POT file for a context, with the strings translated. There is one PO file per translation (i.e. there will be a fr_FR.po file for French, es_ES.po for Spanish, etc.).
  • MO (Machine Object) files are analogous to the PO files, but are machine-readable. The MO files are created from the PO files.

You need to create these files for each translation. Tools including GetText and Poedit can help on both fronts.

Want to dive deeper? Other resources and guides that might be helpful include:

Christopher Carfi
A veteran of both startups and the enterprise, Chris has a deep track record in developing customer community and evangelist programs for brands such as Adobe, H&R Block and Aruba Networks while holding executive positions at Ant’s Eye View and Edelman Digital, and he was co-founder and CEO at Cerado. He currently lives in the Bay Area with his family.