Momergil
31st July 2014, 15:19
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:
//main.cpp
qint32 main(qint32 argc, char *argv[])
{
QApplication::setGraphicsSystem("raster");
//
QApplication app(argc, 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::setDefaultLo cale(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)
{
case CFG::Language_English: QLocale::setDefault(QLocale(QLocale::English,QLoca le::UnitedStates)); break;
case CFG::Language_Espanol: QLocale::setDefault(QLocale(QLocale::Spanish,QLoca le::LatinAmericaAndTheCaribbean)); break;
case CFG::Language_PortugueseBR: QLocale::setDefault(QLocale(QLocale::Portuguese,QL ocale::Brazil)); break;
default: QLocale::setDefault(QLocale::c()); break;
}
}
bool ProfileCenterView::installLanguage(const Config::UserCfgSingletom::AvailableLanguages language) (static)
{
if (language == CFG::Language_English)
return true;
//
QDir translationDir(DEFAULT_TRANSLATION_PATH);
QStringList fileNameList = translationDir.entryList(QStringList("*.qm"),QDir::Files,QDir::Name);
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
QTranslator translator;
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
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:
//main.cpp
qint32 main(qint32 argc, char *argv[])
{
QApplication::setGraphicsSystem("raster");
//
QApplication app(argc, 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::setDefaultLo cale(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)
{
case CFG::Language_English: QLocale::setDefault(QLocale(QLocale::English,QLoca le::UnitedStates)); break;
case CFG::Language_Espanol: QLocale::setDefault(QLocale(QLocale::Spanish,QLoca le::LatinAmericaAndTheCaribbean)); break;
case CFG::Language_PortugueseBR: QLocale::setDefault(QLocale(QLocale::Portuguese,QL ocale::Brazil)); break;
default: QLocale::setDefault(QLocale::c()); break;
}
}
bool ProfileCenterView::installLanguage(const Config::UserCfgSingletom::AvailableLanguages language) (static)
{
if (language == CFG::Language_English)
return true;
//
QDir translationDir(DEFAULT_TRANSLATION_PATH);
QStringList fileNameList = translationDir.entryList(QStringList("*.qm"),QDir::Files,QDir::Name);
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
QTranslator translator;
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