Translation system simply not working!
Hello!
I'm knocking my head for some hours now trying to understand why my translation mechanism is not working despite the fact that I followed all translation manuals and examples (no to mention that to translate seems a pretty easy task). What happens is that I created the .ts files, translated (parts of it) in Qt Linguist, created the .qm files and added them to the specified folder. Then I call QTranslator etc. in my program and both finding the translator files as well as loading them returns no error - but no translation actually occurs in the application.
Here is (most of) the code so you all may check if I missed something:
Code:
//main.cpp
qint32 main(qint32 argc, char *argv[])
{
//
app.setApplicationName("RE8000");
app.setApplicationVersion(APP_VERSION);
app.setOrganizationName("XXXX");
app.setOrganizationDomain("http://www.xxxx.com.br/");
app.
thread()->setPriority
(QThread::HighestPriority);
if (!setTranslation())
CFG_ED.setProfileLanguage(CFG::Language_English);
//Starts creating the widgets
g_mainSplashScreen
= new SplashScreen
(QPixmap(":/Images/EntraceImage.bmp"), Qt
::WindowStaysOnTopHint);
g_mainSplashScreen
->setGeometry
((QApplication::desktop()->width
() - g_mainSplashScreen
->pixmap
().
width())/2,
(QApplication::desktop()->height
() - g_mainSplashScreen
->height
())/2,
g_mainSplashScreen->pixmap().width(),g_mainSplashScreen->height());
}
//...
static bool setTranslation()
{
const CFG::AvailableLanguages currLanguage = CFG_ED.profileLanguage();
Settings::Profile::ProfileCenterView::setDefaultLocale(currLanguage);
if (Q_UNLIKELY(!Settings::Profile::ProfileCenterView::installLanguage(currLanguage)))
{
mLog("An error occured while trying to load the translation file (static bool setTranslation(QApplication&))");
return false;
}
return true;
}
//Other files
void ProfileCenterView::setDefaultLocale(const Config::UserCfgSingletom::AvailableLanguages language) (static)
{
switch (language)
{
}
}
bool ProfileCenterView::installLanguage(const Config::UserCfgSingletom::AvailableLanguages language) (static)
{
if (language == CFG::Language_English)
return true;
//
QDir translationDir
(DEFAULT_TRANSLATION_PATH
);
if (Q_UNLIKELY(fileNameList.isEmpty()))
{
mDebugS("Error while trying to install translator: no translator files were found (ProfileCenterView::installLanguage))");
mLog("No translation files were found");
return false;
}
//![] Install selected translation
if (Q_UNLIKELY
(!translator.
load(QLocale(),
"re8000",
"_",DEFAULT_TRANSLATION_PATH,
".qm"))) {
mDebugS("Error while trying to install translator: error while loading file (ProfileCenterView::installLanguage)");
mLog("Error when trying to load the translation file");
return false;
}
qApp->installTranslator(&translator);
return true;
}
Remember: as I sad, no errors are returned; only the translations don't appear as if I hadn't done any translations to the .ts file (which I did!).
What could be wrong? :(
I'm glad for any help,
Momergil
Re: Translation system simply not working!
Guess what happens to QTranslator instance after the scope where it is declared ends...
Re: Translation system simply not working!
Quote:
Originally Posted by
wysota
Guess what happens to
QTranslator instance after the scope where it is declared ends...
Hmm! So you mean that the QTranslator object need to be kept alive during the whole translation process, not only for the QTranslator::load() operation? Well, I'll check that out after dinner and return with the results!
Re: Translation system simply not working!
Think why you are passing a pointer to the object to installTranslator...
Re: Translation system simply not working!
Quote:
Originally Posted by
wysota
Think why you are passing a pointer to the object to installTranslator...
hmm, ok, you certainly made a point :)
So now the QTranslator inside my installLanguage method is a static one and everything is working 'fine' :) The other problem I'm having was mentioned here.
Thanks,
Momergil
Re: Translation system simply not working!
QTranslator is a QObject so you can create it on heap passing a parent to it and then forget about the object if you don't have functionality for dynamically unloading translations in your application.