Closed hyyan closed 9 years ago
Can you expand on the issue you are encountering please? I'm not 100% sure what you mean.
You could also try the changes in #110 that make the autoloaded plugins load first instead of last (but be mindful of the caveats I mention in that PR).
@Foxaii What I am trying to do is to load translation file for my plugin which must be loaded by bedrock-autoloader , the plugin is simple branding plugin , Here is a snippet :
/*
* This file is part of the SARC package.
* (c) Hyyan Abo Fakher@Guestra <tiribthea4hyyan@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Plugin Name: Guestra Branding
* Description: Brand this wordpress installation for Guestra
* Author: Guestra
* Author URI: http://www.guestra.net
*/
add_filter('Hyyan\Dashboard.options', 'guestra_dashboard_plugin');
add_action('admin_bar_menu', 'geustra_contact_menu', 9999);
add_action('plugins_loaded', 'guestra_lang');
/**
* Add the plugin translation
*/
function guestra_lang() {
load_plugin_textdomain(
'guestra'
, false
, trailingslashit(basename(dirname(__FILE__))) . 'languages/'
);
}
Now as you can see from the snippet the translation files will not be loaded because the autoloader itself use plugins_loaded
hook to make its job done . and the question is what hook should I use instead ??
Note :
the plugin works fine if I use it as standard wordpress plugin offcourse
It would be helpful if you could try two fixes and report back which worked (it should be both):
plugins_loaded
action to muplugins_loaded
here @Foxaii I've just tried what you proposed to do , But it didn't work
@hyyan It will take some further digging. I'll have a look into it tomorrow or over the weekend.
This isn't anything autoloader related.
If you look at the parameters of load_plugin_textdomain
the full path option has been deprecated, so the only path you can use must be relative to the plugin directory, not the mu-plugin directory.
@Foxaii I know that , but the method in my snippet return relative path not a full path , I am already aware of the second deprecated param . What we are missing here is the right hook to load translation file , in normal plugins we use load_plugin_textdomain
and in mu-plugins we use load_muplugin_textdomain
but none of these methods works with autoloader , Is there any alternative hook to use with autloader so the translation file will be loaded ?
@Foxaii I think there is must a bedrock autoloader hook like wordpress native hooks to mark that plugins have loaded by the autoloader for example bedrock_plugins_loaded
, but I am not really sure if something like that will solve the problem , What do you think?
Your translation files are in the mu-plugins
directory, but the load_plugin_textdomain
function takes the relative path to those files and prepends the path to the plugins
directory, so it's not looking where the translation files are.
If you apply the changes in #110 and then use the load_muplugin_textdomain
hook it should work, as it will be looking in the correct folder.
I'm not sure if additional hooks are the answer but will look into it.
@Foxaii It is still not working , even with #110 changes, I don't why ??? I think I will use the plugin as standard wordpress plugin for now until the solution become available , Thanks anyway
I'm not sure if you ever got this working as you intended, but the way I use translations is by creating an languages/plugin
folder in app
that contains my-plugin-name-en_GB.mo
and my-plugin-name-en_GB.mo
.
@Foxaii Almost 10 years later I have the same trouble. :)
The mu-plugin is with stalled with composer.
Create app/languages/plugin
is not a nice solution, i want my transations inside my plugin directory.
What hook should I use to load translation when I use bedrock-autoloader to load my plugin ?