Text Domains Across Multiple Plugins & Themes

A common situation: a developer builds an entire site, based on WordPress, of course, for a client.

This site includes many custom plugins as well as a custom theme — maybe another theme or a child theme or two for good measure.

Doesn’t make a lot of sense for all those custom plugins and such to have their own text domain. A single translator will probably doing all the work. It’s also probably much easier to maintain a single set of translations.

So, how does one use a single text domain across multiple plugins and/or themes?

Just so we’re clear, I want the equivalent of load_plugin_textdomain and load_theme_textdomain that I can use for multiple plugins/themes.

1
1

You don’t. Translations are part of each item’s commit history, they should be kept as separate as the PHP code. In terms of performance, you don’t win much with a combined text domain. Actually, you could lose performance, because if you need that one translation array almost everywhere, you cannot load it selectively anymore or destroy it when you don’t need it.

One way to do what you want, is a separate plugin, maybe named “Client Name translations”, duplicate all strings in that and let the translators translate this file only. Prepare for sync hell. 🙂

Or you move all strings to a separate file with a single array …

<?php 
return array(
    'name1' => __( 'Name one', 'your_text_domain' ),
    'name2' => __( 'Name two', 'your_text_domain' )
);

… and require_once that file in all other sub-projects (or write a wrapper plugin for it). Then you access the strings by their keys.

But I would try to keep separate commit histories for all projects. Once you want to reuse one of them you have to rewrite everything anyway.

Leave a Comment