• Resolved htmgarcia

    (@htmgarcia)


    Anyone have a suggestion to load two .mo files for a plugin? Both using the same text domain.

    As example:

    text-domain-es_ES.mo
    text-domain-es_ES.custom.mo

    The second file would override some strings from the first one.

    • This topic was modified 4 years, 8 months ago by Jan Dembowski.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Dion

    (@diondesigns)

    load_plugin_textdowmin() calls load_textdomain():

    https://developer.www.ads-software.com/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.

    Thread Starter htmgarcia

    (@htmgarcia)

    Thanks for jumping into the discussion, @diondesigns!

    You mean load_plugin_textdomain(), correct?

    Dion

    (@diondesigns)

    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.

    Thread Starter htmgarcia

    (@htmgarcia)

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

    Dion

    (@diondesigns)

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

    Thread Starter htmgarcia

    (@htmgarcia)

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

    Thread Starter htmgarcia

    (@htmgarcia)

    @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!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to load two .mo files for the same plugin?’ is closed to new replies.