2

Context: I have created a plugin that is enabled only at the network level and it handles certain synchronizations between the child sites. As it is a network level plugin, it has its menu added to the network dashboard instead of the admin dashboards of child sites.

Problem: I have implemented internationalization in the plugin following strict practices from the WordPress codex. For some reason, the load_plugin_textdomain function cannot load the .mo files I have generated. I have verified the path that is created, I have verified the text domain to be correct everywhere and yet the following code returns false.

    function bgm_load_textdomain(){
        load_plugin_textdomain( 'bgm', false, plugin_dir_path(__FILE__) . 'languages/'); //returns false
    }
    add_action( 'init', 'bgm_load_textdomain' ); //also tried this with the plugins_loaded hook

I have already checked the following:

  1. The file permissions for the .mo files and folder, they are readable.
  2. I have the Text Domain added in the main plugin file and double checked for any spelling or placement errors.

Question: Does WordPress network admin dashboard not facilitate the load_plugin_textdomain function? Is there a specific reason why the .mo file is not being loaded in my scenario and is it because my plugin is one to be used only via the network dashboard? Because I seem to be following the best practices and I have tried the solutions available but the .mo file just wouldn't load, this function is constantly returning false.

Please respond if this is a known blackhole and if there exists a work-around.

P.S - I have generated the .mo files using the Loco Translate plugin and it picked up the text-domain and related strings automatically without producing any errors.

2
  • is __FILE__ the main plugin file? I notice your never declare that the debug function accepts 2 parameters when you used add_action
    – Tom J Nowell
    Mar 10, 2021 at 16:49
  • Yes, it's the main plugin file. And you're right about the debug function, I will omit that part from the question. Thanks
    – Talha Imam
    Mar 10, 2021 at 17:08

1 Answer 1

1

The third parameter to load_plugin_textdomain function should only be the plugin name suffixed with the language folder. It does not need the absolute path to the language folder.

For e.g. in my scenario, the correct parameter is:

load_plugin_textdomain( 'bgm', false, basename(__DIR__)  . '/languages/');

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.