1

From start: A = main plugin(the library), B = child plugin

I develop a plugin B that will depend on another plugin A in order to work properly. I do this because I'm one of the persons who don't like code duplication. So I have a plugin with the library required for other plugins A and another plugin that will do only what it should but only if plugin A is activated.

Everything is working well, but... I also need to make the plugin B independent and to archieve this I must include the main library. Is simple and all I need to do is to change a few lines of code.

Here is the potential problem. In plugin A I have the translation text domain example_text_a and in the child plugin(B) it is example_text_b.

Both are using something like this to load the languages:

add_action( 'plugins_loaded', 'example_load_translations' );
function example_load_translations() {
    load_plugin_textdomain( 
        'example_text_X', 
        false, 
        dirname( plugin_basename( __FILE__ ) ) . '/languages/' 
    ); 
}

Now the question. Is it possible to load two different lang text domains in a single plugin? And if YES, will cause this any conflicts?

I would apreciate more help regarding localization if possible. Thank you.

2
  • Take a look at this question - reached my voting limit today, otherwise I would have suggested it as duplicate. Commented Aug 20, 2014 at 11:16
  • 1
    It's not an direct answer to your question. But if you want to make sure for plugin b to work to have plugin a installed and active, you could always use TGMPA ^^ so you don't have to deliver Library A always Commented Nov 22, 2021 at 7:53

1 Answer 1

2

Yes, you can load multiple translation files for multiple text domains in one plugin. This is sometimes useful, for example when you need just one string in AJAX calls and many strings in the rest of the application: to make AJAX faster, load a separate translation.

Be aware, automatic language updates for the plugin from wordpress.org will probably not work with that, they don’t expect more than one translation.

Never ever use plugins_loaded to load a translation. You don’t create output here. Wait for the first call to a translation function, make sure you don’t load the translation when it isn’t needed. The comment post file, XML RPC or AJAX are common places where plugins slow down everything without any benefit.

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.