Localizing Plugins and Themes

2004 November 1
by Ryan

Currently, plugins and themes cannot be localized because their strings are not in the default WP catalog. To remedy this, I added the ability for plugins and themes to load their own catalogs.

To localize a plugin, call load_plugin_textdomain() at the top of your plugin, passing it a string to identify the domain.

load_plugin_textdomain('myplugin');

load_plugin_textdomain() looks in the plugin directory for a file called $domain-$locale.mo where $domain is the textdomain specified in the call to load_plugin_textdomain() and $locale is the language and country code specified in WPLANG. If WPLANG is en_AU and the domain is “myplugin”, the file loaded is wp-content/plugins/myplugin-en_AU.mo.

Now, when you markup strings in your plugin, you must specify the domain in the calls to __() and _e().

__('String to translate.', 'myplugin');

With all strings marked in this manner, your plugin is ready for localization. You just need to generate a POT file and give it to translators.

Theme catalogs are loaded with load_theme_textdomain(). load_theme_textdomain() looks in the active theme directory for a file called $locale.mo. Strings are marked in the same way that plugin strings are marked.

In summary, load_plugin_textdomain() and load_theme_textdomain() load translation catalogs for plugins and themes, respectively. __() and _e() now take a second argument which specifies the catalog in which to lookup strings. You must specify a domain when loading catalogs and marking strings for plugins and themes.

I’ll start localizing the Kubrick theme for 1.3 sometime soon. Mustering the motivation to start such a tedious task is difficult.

12 Responses

Trackbacks & Pingbacks

  1. WordPress.ch » Blog Archive » Thèmes et greffons: comment se préparer à WP 2.0?
  2. 土路托的世界 » 编写WordPress插件(三)
  3. contact-sheet.de / blog » Blog Archive » Arbeiten an neuem Theme und Übersetzungen
  4. aNieto2K » Blog Archive » Hagamos las cosas bien
  5. Arbeiten an neuem Theme und Übersetzungen » contactsheet.de
  6. WordPress Themes und Mehrsprachigkeit » contactsheet.de
  7. Scrivere un plugin per WordPress / Pixline
  8. ALTERNATE-REALITY.NET » Blog Archive » Making wordpress multi-lingual
  9. Tilrettelegge temaer og innstikk for oversettelse | Norsk WP
  10. Weblog Tools Collection » Blog Archive » Localizing a WordPress Plugin Using poEdit
  11. Nico Nemil | Filipino Web Developer | Pinoy Web Designer | Intermediate Graphics Artist » Localizing a WordPress Plugin Using poEdit
  12. Como internacionalizar o seu plugin para wordpress » Paulo Duarte

Comments are closed for this entry.