2

My plugin is in: /root/.../mu-plugins/my-plugin

In /root/.../mu-plugins/my-plugin/languages/ I have the following files:

  • my-domain.pot
  • my-domain-fr_CA.po
  • my-domain-fr_CA.mo

The strings I want to translate are setup as:

'title' => __('Options', 'my-domain'),

I have the following code in the main plugin file (my-plugin/my-plugin.php):

add_action( 'init', function() {
    $plugin_rel_path = dirname( plugin_basename(__FILE__) ).'/languages/';

    load_muplugin_textdomain( 'my-domain', $plugin_rel_path );
} );

I've played around and tried various things suggested elsewhere, such as using plugins_loaded, muplugins_loaded, but the consensus seems to say that this must be loaded on the init hook.

When var_dumping $plugin_rel_path I get the value "my-plugin/languages/" which seems to be what I need as it needs to be a relative path from the MU plugin folder.

That being said, no matter what I try, the strings never get translated.

I seem to understand that the trailing slash is necessary but I have tried without.

My domain does not match my plugin name and I've considered that this could be an issue but from what I'm reading it shouldn't be as you pass the domain you want loaded to the function. If someone knows better I'd really appreciate some clarifications. I've translated plugins before, and while I find it somewhat unintuitive, it's always worked.

Edit: I'd like to mention that I am using the bedrock mu-plugin autoloader. I don't know if that makes a huge difference but they do act slightly different than regular mu-plugins which are supposed to be files on the root level. I'm still sending in the path to the language folder.

5
  • 1
    Might be worth double checking without the trailing slash, as that should not be used. Otherwise I'm not seeing anything wrong...
    – vancoder
    Commented Jan 4, 2023 at 22:34
  • Looking at the source for load_muplugin_textdomain() I agree that the trailing slash is likely the problem. Commented Jan 5, 2023 at 6:53
  • 1
    I misspoke and the trailing slash is not necessary but the issue persists even without. I hacked a solution together by moving my translated files to the default WP one but I would have much rather keep them in the plugin folder.
    – Gazillion
    Commented Jan 5, 2023 at 15:24
  • "they do act slightly different than regular mu-plugins which are supposed to be files on the root level" - can you elaborate? You are using load_muplugin_textdomain, which will only work if your plugin resides at the location represented by the WPMU_PLUGIN_DIR constant.
    – vancoder
    Commented Jan 6, 2023 at 17:25
  • MU plugins don't work like regular plugins. The bedrock loader is a script that lets you slide plugin folders in the MU folder and it loads them automatically. My plugins are all in the MU folder but in their respective folders (yoast, for example, would be in the /mu-plugins/yoast/ folder and its language file would be in /mu-plugins/yoast/languages/). I don't think this is the cause of my issue because, like you said, load_muplugin_textdoamin uses the WPMU_PLUGIN_DIR as its root and looks for the relative path that I pass.
    – Gazillion
    Commented Jan 6, 2023 at 18:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.