7

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.

2
  • This question is pretty old now. Did you manage to find a good solution to this issue?
    – Swen
    Commented Jul 18, 2017 at 11:48
  • Nope. What I was trying to do was managing translations across a single site with an assortment of custom plugins and themes. I think @fuxia is right though, looking back on it now: shouldn't be done. Commented Jan 30, 2018 at 20:01

1 Answer 1

3

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.

1
  • 1
    Everything is a single repo, so it's one commit history. Commented May 10, 2013 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.