How to load two .mo files for the same plugin?

load_plugin_textdowmin() calls load_textdomain():

https://developer.wordpress.org/reference/functions/load_textdomain/

It would appear that the custom .mo file must be loaded first. That definitely seems counter-intuitive, but…try it and see if it works.

Thanks for jumping into the discussion, @diondesigns!

You mean load_plugin_textdomain(), correct?

load_plugin_textdowmin() calls load_textdomain() to do all the “heavy lifting”. That’s why I posted the developer notes for load_textdomain().

So try loading the custom .mo file first and see if it works the way you want.

I get your point, however I can’t find any documentation about load_plugin_textdowmin(). I thought you probably made a typo.

That’s because it’s a typo. 🙂 Try load_plugin_textdomain(), or you can call load_textdomain() directly if you prefer.

That’s what I said in the two previous messages 😂

@diondesigns it worked by calling the functions in this order:


load_textdomain() // The specific mo file with overrides
load_plugin_textdomain() // Point to the plugin's languages/ folder

Example code if is helpful for someone else:


function your_language_domain_init()
{
    // Load override language file first
    load_textdomain(
        'plugin-text-domain',
        'path/to/file.mo'
    );

    // Loads translated strings from plugin's languages/ folder
    load_plugin_textdomain(
        'plugin-text-domain', 
        null, 
        dirname(plugin_basename(__FILE__)) . '/languages/'
    );
}
add_action( 'init', 'your_language_domain_init' );

____
Thanks for your help!



Source link