Finer Points of Text Domain in WordPress Internationalization

This article from Pascal Birchler about text domain in plugins got into some territory I’d not considered. I shouldn’t be surprised, Pascal is very smart, a regular contributor to WordPress itself.

Discussing it in light of a new WP-CLI command that he’s working on to make plugin translation easier, Pascal highlights the idea that a plugin should have a single text domain slug, like my-plugin, and that you should use that everywhere in the code. That’s relatively common knowledge among people who both consider themselves developers and know that i18n is short for “internationalization.”

What’s I’d not considered is what you should do when your WordPress plugin either extends an existing plugin, or pulls in some external code automagically for you. That’s where I found Pascal most interesting:

A similar situation [that you want to always use your plugin’s text domain] arises when adding customized WooCommerce shop templates to your WordPress theme. Usually you don’t need to add these to your theme unless you really need to change the markup.

Since these templates are coming from the WooCommerce plugin, all localizable strings use the woocommerce text domain. And when you don’t change any of these strings you might consider just keeping the text domain so WordPress will still translate these.

However, not changing the WooCommerce text domain is a bad idea. The reasons are simple:

  1. Strings with a different text domain than your theme’s might not be extracted in the future.
  2. It’s unreliable.
    When WooCommerce changes its templates in a new version, your strings might suddenly not be localized anymore.
  3. You take control away from users.
    Users and translators have no way to translate your customized shop templates.
  4. Context might change.
    When you heavily customize the WooCommerce templates, some of the strings in them might not be 100% accurate anymore. At this point you have to rephrase and use your own text domain anyway.

For the same reasons you shouldn’t use WordPress core strings, without your project’s text domain, in your plugin or theme either.

My take on this broader topic of internationalization in WordPress is called “Making Plugins and Themes Translation Ready,” by the way. 🤓


Add a Comment

Your email address will not be published. Required fields are marked *