Question

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.

Was it helpful?

Solution

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/');
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top