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.
load_muplugin_textdomain()I agree that the trailing slash is likely the problem.load_muplugin_textdomain, which will only work if your plugin resides at the location represented by the WPMU_PLUGIN_DIR constant.load_muplugin_textdoaminuses the WPMU_PLUGIN_DIR as its root and looks for the relative path that I pass.