Plugin and internationalization
Hi!
I build my plugins, but can't load compiled language files.
Plugins automatically don't load language files that's lie near. (Becase it do QCore... class)
When I try to put phrases into main application langugage file, nothing happense too.
I Know that we can use Language loading by hand, but don't know how set this language file for plugin. (only for Application)
Re: Plugin and internationalization
You have to load the files manualy into the translators while initialising plugins.
Re: Plugin and internationalization
You mean I need load translations in main application?
And then tell to plugin thats we load it ?
Maybe a little sample of code ?:o
Re: Plugin and internationalization
Hmm... Your plugin class should contain a method to create a translator ready to install, something like:
Code:
struct MyPluginInterface {
virtual ~MyPluginInterface(){};
// ...
};
Your plugin should implement it like so:
Code:
// you may need to change "this" to something else above
translator->load(":/translations/"+locale+".qm");
return translator;
}
And your main app:
Code:
QObject *plugin
= loader.
instance();
if(plugin){
MyPluginInterface *piface = qobject_cast<MyPluginInterface*>(plugin);
qApp->installTranslator(piface->translator("pl_PL");
}
You can try to load the translator directly from the plugin too instead of doing it in the main app.
Re: Plugin and internationalization
You mean that's "tr" function used in plugin will be traslated by "qm" loaded from main application...
Yes, plugin can't define his translator by default, but we can inherit QTCore....
Today i try your way.
Re: Plugin and internationalization
Quote:
Originally Posted by blackliteon
You mean that's "tr" function used in plugin will be traslated by "qm" loaded from main application...
Yes, sure.
Quote:
Yes, plugin can't define his translator by default, but we can inherit QTCore....
I don't understand what you mean here. Definitely not "inherit". You can have only one QCoreApplication object in an application. But there is a global pointer to a QApplication object available, so you can use it anywhere.
Re: Plugin and internationalization
If I understand you when we use tr everywhere we use QCoreApplication ?
Re: Plugin and internationalization
tr() is just a call which uses an installed translator to get a translation for a string. Translators are installed in the application object, so yes, if you use tr() a call to the application object is made behind the scene.
Re: Plugin and internationalization
So we use installTranslator function for each translator.
You mean that's translator add language phrases
I mean that if we load for every plugin his translational file all of them will be summed (phrases) ?
Re: Plugin and internationalization
Quote:
Originally Posted by blackliteon
I mean that if we load for every plugin his translational file all of them will be summed (phrases) ?
Yes, they will.
Re: Plugin and internationalization