1

I have a bunch of plugins. Obviously, they all have their own unique textdomains for internationalization (i18n).

I also have a bunch of files that I include in all my plugins - I throw them all in a directory called common. This adds a dashboard widget that I want all my plugins to have, as well as a script for updating (since they don't live on the wordpress.org plugin repo).

I want to be able to just drop my common folder into each of my plugins without having to edit the files. But I'm concerned about the text strings contained inside.

Can I call load_plugin_textdomain twice, for two different domains, within the same plugin? What's the best way of handling this situation with i18n in mind?

Or will I have to go through each instance of my common files and manually change the textdomain to match the plugin?

1

You can call load_plugin_textdomain() multiple times in each plugin, but I would not do that.

Put the common files into a separate plugin, for example luke-carbis-library. In that plugin create two simple functions for setup and loading extra files:

add_action( 'plugins_loaded', 'lcl_init' );

function lcl_init()
{
    $dir = plugin_dir_path( __FILE__ );
    $url = plugins_url( __FILE__ );

    // maybe load necessary files and translation

    do_action( 'lcl_init', $dir, $url );
}

function lcl_load( $file )
{
    require_once plugin_dir_path( __FILE__ ) . $file;
}

In your depending plugins hook into your custom action:

add_action( 'lcl_init', 'depending_plugin_init', 10, 2 );

Now you can change the inner structure of the base plugin any time; the other plugins just use $dir and $url from your hook.

  • More work than I was hoping for - but I agree, this is definately the best way to go. Thanks. :) – Luke Carbis May 23 '13 at 18:02
  • Still have a problem though - if I prompt my users to install the luke-carbis-library plugin when it's not installed, what textdomain do I use for the message? I'll still need to put a 'prompt' in every plugin, and I don't want to have to change the textdomain every time. Thoughts? – Luke Carbis May 23 '13 at 19:05
  • @LukeCarbis This one message will be duplicated in all plugins, using each plugin’s own text domain. I wouldn’t worry about one string. – fuxia May 23 '13 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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