Open tsteur opened 1 year ago
I'm actually not sure if the order plugins are loaded in is something that anyone should rely on. The order might be some sort of random, depending on when a plugin is installed and/or activated. Maybe in case of translations it would be more useful to provide events that allow manipulating them?
I think we may need a combination of both approaches, both the order and some way to manipulate it. The result should be predictable, whichever way we arrive there.
I'm actually not sure if the order plugins are loaded in is something that anyone should rely on.
We sort the plugins in the right order in PluginList::sortPluginsAndRespectDependencies()
when activating/deactivating plugins. This way we don't need to sort them on every request. It's 99% reliable unless someone manually edits the config file.
This is being used to make sure non-core plugins can overwrite core plugins with components, metrics, events, ... and it also makes sure that if "Non-Core Plugin A" requires "Non-Core Plugin B", that "Non-Core Plugin A" can overwrite things from "Non-Core Plugin B" which we are doing in few cases.
So effectively, the config.ini.php has the plugins stored in the right order in which they should be processed (unless someone edits it manually).
I guess we could simply sort the plugins in the loadPluginTranslations
, but the directories are for some reason also added in loadAllPluginsAndGetTheirInfo
. Guess we need to check why that is done and maybe remove it if not needed or simply call loadPluginTranslations
instead.
@sgiehl for consistency, we would just need to use same behavior as Manager::findComponents
and EventDispatcher::postEvent
and use $plugins = $this->getPluginsLoadedAndActivated();
. Then things should come out in the right order for us.
Context
By default, triggered events and components are executed/loaded by the order of the plugins.
However, this is not the case for plugins. Thus it loads translations by plugin alphabetically. This means translations of
Cloud/en.json
may be loaded beforeCoreHome/en.json
. As a result, it's not reliably possible to overwrite translations from core.Eg in
Cloud/en.json
I wanted to put in below to overwrite a translation:Expected Behavior
Plugins are loaded in the correct order. This way, non-core plugins can overwrite translations / wordings of core plugins without needing to write a custom loader (like it was done in https://github.com/Findus23/plugin-CustomiseTranslations/blob/5.x-dev/config/config.php to workaround this problem).
Current Behavior
They are loaded in alphabetical order.
Possible Solution
Use
PluginList::sortPlugins
to sort plugins before adding language directories inPlugin/Manager::loadPluginTranslations()
.Steps to Reproduce (for Bugs)
ABC
plugins/ABC/lang/en.json
{ "CorePluginsAdmin": { "MenuPlatform": "Export" }}
Your Environment
Matomo 5.0 RC4