You must use different domains for each plugin. A domain can be a package name to prevent conflicts.
I donβt understand why you need to translate something outside the plugin using the plugin domain, but if you really need to, you must change the domain every time.
Each plugin can provide it with its own "undescore", easily bound to the plugin domain:
from my.plugin import MessageFactory as _my_plugin
Please note that underlining is only a convention, so extraction tools may find i18n messages in the program. Plugin messages should be underlined in their respective packages (you put them in separate packages, right?). In all other places, you can call these factories by some other name and leave an underscore for the main domain of translation of the program.
I'm less sure about .mo files, but you can compile all your .po files into a single .mo file. However, if the plugins are written by independent inconsistent authors, there may be message conflicts.
UPDATE:
If the plugins are in the same package with the main application, then it makes no sense to use separate imperial domains for them (this is not your case). If the plugins are in separate packages, then for these packages you must run them yourself. In both cases, you have no problem with the variable _. If for some reason the main application wants to translate plugins into your code, use a different name for _, as in the answer. Of course, extraction tools will not identify anything other than underscores.
In other words, plugins must take care of their translations themselves. The main application can use the translation function associated with the plugins as part of the plugin API. Extracting or manually adding lines to po / mo files is also not related to the main application: its plug-in developer is provided with a translation.
source share