[SOLVED] Translations in static library and their usage
-
Hi!
I have made a static library named QAstrologyLib, and I have translated the few strings it has into Catalan. Then I have written a little program that uses this library.
I thought that the translations would be automatically included into the static library, but I have to point where they are, otherwise it doesn't find the translation:
@int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTranslator translator;
translator.load("/home/david/devel/QASTROLOGYLIB/src/qastrologylib_ca");
app.installTranslator(&translator);
EphemerisList ephemerisList;
ephemerisList.show();
return app.exec();
}@I could insert the translations as resources in the library, but then, what's the path I have to use from the program to load the translation, since they are the library's resources?
Thank you very much!
-
Hi David,
an absolute path in your program is not a good design strategy. And why did you create an static lib instead of a dynamic lib?As you mention it would be better to add the translation file as resource. The URL is quite simple.
Same like icons. ":/MyTranslations/qastrologylib_ca.qm"/MyTranslation/ is the prefix which you can choose freely.
Best regards
-
Hi!
I created a static lib because it's so small and new that I can't expect anyone to have it installed. For some time, I want to be able to deploy my programs in one single file.
I have added the translation files as resources in the QAstrologyLib project, with the prefix "/" and the name of the qrc file "i18n.qrc".
Then, I discovered that I have to use "Q_INIT_RESOURCE":http://qt-project.org/doc/qt-4.8/qdir.html#Q_INIT_RESOURCE
@#include <QApplication>
#include <QTranslator>#include <QDebug>
#include "ephemerislist.h"int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Q_INIT_RESOURCE(i18n);QTranslator translator; qDebug() << translator.load(":/qastrologylib_ca"); app.installTranslator(&translator); EphemerisList ephemerisList; ephemerisList.show(); return app.exec();
}@
Thank you for your advice :-)
David Gil