Skip to main content
Dublin Library

The Publishing Project

Internationalizing WordPress Themes and Plugins (part 1)

 

According to [GALA (Globalization and Localization Alliance)](https://www.gala-global.org/language-industry/intro-language-industry/what-internationalization): > Internationalization is a design process that ensures a product (usually a software application) can be adapted to various languages and regions without requiring engineering changes to the source code. Think of internationalization as readiness for localization... Some practical examples of how internationalization is critical to multilingual products include: > > - Independence from a specific language/character set encoding > - Independence from specific cultural conventions > - Removal of hard-coded text > - Minimization of concatenated text strings > - Careful use of in-line variables > - Compatibility with third-party tools > - Unicode compliance for global text display > - Accommodation of double-byte languages (for example, Japanese) > - Accommodation of right-to-left languages (for example, Arabic) In the context of WordPress, internationalization means at least two things: - Ensuring that the text in our themes and plugins is ready for localization - Making sure that we consider right-to-left languages The strategies for internationalizing plugins and themes are slightly different so we'll cover them separately. ## Internationalization tools in WordPress WordPress translation infrastructure is built on top of [GNU Gettext](https://www.gnu.org/software/gettext/) so that's a good starting point for research. The rest of he post is WordPress Specific. ### Text Domain The text domain provides WordPress with a unique identifier for our plugin or theme. This is important because WordPress will have many plugins and a theme to sort through so having unique names makes things easier. In a theme, the text domain and the domain path, the location of our translated files, is placed on the root CSS style sheet. For our `my-demo-theme` theme this is placed in a comment inside `style.css`. ```php /* * Theme Name: My Theme * Author: Theme Author * Text Domain: my-demo-theme * Domain Path: /languages */ ``` For plugins, the Text Domain and Domain path are placed in a comment on the root PHP file, either index.php or the root of the plugin code. ```php /* * Plugin Name: My Plugin * Author: Plugin Author * Text Domain: my-demo-plugin * Domain Path: /languages */ ``` ### i18n functions There are several i18n functions available for PHP internationalization The most basic one is [\_\_()](https://developer.wordpress.org/reference/functions/__/) that will just translate its content. ```php

``` ### Variables What if you have a string like the following: ```php Edit on Github