Closed Jaspervv closed 5 years ago
Thanks for reporting this one.
Regarding the plugin relative path, I suggest to add a method to the PluginManager
class so we get simply do this:
load_plugin_textdomain(
$plugin->getHeader('text_domain'),
false,
$plugin->getRelativePath())
);
And now regarding the helper function, can you describe where do you actually define it ? You seem to pass the plugin directoy as a parameter, using your function from a plugin root, the following snippet is supposed to work, right ?
<?php
// Plugin headers
// ....
loadThemosisPluginTextDomain($plugin->getDirectory());
I made the function wrapper for this issue, we currently have the code without it being inside a function. (don't worry, I did test it 😋)
loadThemosisPluginTextDomain($plugin->getDirectory());
does indeed work, that would also be the best way to use it dynamically.
I made an issue instead of a pull request because I have no idea what a good place for the function would be.
@Jaspervv I've currently developped an application textdomain function inside the Core/helpers.php
called load_application_textdomain
in order to set translations files on the application root. We could add your function there as well certainly so it is sure that it is available on all plugins and mu-plugins.
https://github.com/themosis/framework/blob/master/src/Core/helpers.php#L279
@Jaspervv I'm already working on a solution for this. I'm adding a load_themosis_plugin_textdomain
function to handle correct .mo file loading.
Current code
Currently textdomains are loaded in the code here like so:
This doesn't work tho because the function
load_plugin_textdomain
makes use of the constantWP_PLUGIN_DIR
and requires a relative path, not an absolute one like is given.Fixed code
Here the last parameter uses a relative path:
Dynamic function
We also had an issue that, when our plugin was installed as a must-use plugin, it wouldn't work since that requires the
load_muplugin_textdomain
function.So we made our own function, based on the
load_muplugin_textdomain
function, that works when the plugin is installed as either a muplugin or regular plugin: