Commit 12bb71f0 authored by sankhesh's avatar sankhesh

BUG: Load translations before instantiating the GUI

Moved loadTranslations() and loadLanguage() methods from qSlicerApplicationHelper
to qSlicerCoreApplication. This enables loading them before instantiating the
main Slicer GUI.
Many thanks to zengwenye <iamzengwenye@163.com> for submitting the patch.
Fixes issue 2836

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21559 3bd1e089-480b-0410-8dfb-8563597acbee
parent e980b386
......@@ -99,8 +99,6 @@ int SlicerAppMain(int argc, char* argv[])
return app.returnCode();
}
// We load the language selected for the application
qSlicerApplicationHelper::loadLanguage();
#ifdef Slicer_USE_QtTesting
setEnableQtTesting(); // disabled the native menu bar.
......
......@@ -22,7 +22,6 @@
// Qt includes
#include <QSettings>
#include <QTranslator>
// Slicer includes
#include "qSlicerApplication.h"
......@@ -130,56 +129,6 @@ void qSlicerApplicationHelper::setupModuleFactoryManager(qSlicerModuleFactoryMan
moduleFactoryManager->setVerboseModuleDiscovery(app->commandOptions()->verboseModuleDiscovery());
}
//----------------------------------------------------------------------------
void qSlicerApplicationHelper::loadTranslations(const QString& dir)
{
qSlicerApplication * app = qSlicerApplication::application();
Q_ASSERT(app);
QString localeFilter =
QString( QString("*") + app->userSettings()->value("language").toString());
localeFilter.resize(3);
localeFilter += QString(".qm");
QDir directory(dir);
QStringList qmFiles = directory.entryList(QStringList(localeFilter));
foreach(QString qmFile, qmFiles)
{
QTranslator* translator = new QTranslator();
QString qmFilePath = QString(dir + QString("/") + qmFile);
if(!translator->load(qmFilePath))
{
qDebug() << "The File " << qmFile << " hasn't been loaded in the translator";
return;
}
app->installTranslator(translator);
}
}
//----------------------------------------------------------------------------
void qSlicerApplicationHelper::loadLanguage()
{
qSlicerApplication * app = qSlicerApplication::application();
Q_ASSERT(app);
// we check if the application is installed or not.
if (app->isInstalled())
{
QString qmDir = QString(Slicer_QM_DIR);
Self::loadTranslations(qmDir);
}
else
{
QStringList qmDirs = QString(Slicer_QM_OUTPUT_DIRS).split(";");
foreach(QString qmDir, qmDirs)
{
Self::loadTranslations(qmDir);
}
}
}
//----------------------------------------------------------------------------
void qSlicerApplicationHelper::showMRMLEventLoggerWidget()
{
......
......@@ -41,10 +41,6 @@ public:
static void setupModuleFactoryManager(qSlicerModuleFactoryManager * moduleFactoryManager);
static void loadTranslations(const QString& dir);
static void loadLanguage();
static void showMRMLEventLoggerWidget();
static void initializePythonConsole(ctkPythonConsole* pythonConsole);
......
......@@ -24,6 +24,8 @@
#include <QMessageBox>
#include <QTimer>
#include <QNetworkProxyFactory>
#include <QSettings>
#include <QTranslator>
// CTK includes
#include <ctkErrorLogFDMessageHandler.h>
......@@ -283,6 +285,9 @@ void qSlicerCoreApplicationPrivate::init()
}
#endif
// We load the language selected for the application
q->loadLanguage();
}
//-----------------------------------------------------------------------------
......@@ -1395,3 +1400,53 @@ void qSlicerCoreApplication::terminate(int returnCode)
// Does nothing if the event loop is not running
this->exit(returnCode);
}
//----------------------------------------------------------------------------
void qSlicerCoreApplication::loadTranslations(const QString& dir)
{
qSlicerCoreApplication * app = qSlicerCoreApplication::application();
Q_ASSERT(app);
QString localeFilter =
QString( QString("*") + app->settings()->value("language").toString());
localeFilter.resize(3);
localeFilter += QString(".qm");
QDir directory(dir);
QStringList qmFiles = directory.entryList(QStringList(localeFilter));
foreach(QString qmFile, qmFiles)
{
QTranslator* translator = new QTranslator();
QString qmFilePath = QString(dir + QString("/") + qmFile);
if(!translator->load(qmFilePath))
{
qDebug() << "The File " << qmFile << " hasn't been loaded in the translator";
return;
}
app->installTranslator(translator);
}
}
//----------------------------------------------------------------------------
void qSlicerCoreApplication::loadLanguage()
{
qSlicerCoreApplication * app = qSlicerCoreApplication::application();
Q_ASSERT(app);
// we check if the application is installed or not.
if (app->isInstalled())
{
QString qmDir = QString(Slicer_QM_DIR);
app->loadTranslations(qmDir);
}
else
{
QStringList qmDirs = QString(Slicer_QM_OUTPUT_DIRS).split(";");
foreach(QString qmDir, qmDirs)
{
app->loadTranslations(qmDir);
}
}
}
......@@ -285,6 +285,9 @@ public:
Q_INVOKABLE void setDICOMDatabase(ctkDICOMDatabase* dicomDatabase);
#endif
static void loadTranslations(const QString& dir);
static void loadLanguage();
public slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment