Commit 414a282d authored by Ludovic Fauvet's avatar Ludovic Fauvet

Use the LanguageHelper class for loading the locale.

Also avoid code duplication.
parent 9345f57d
......@@ -25,6 +25,7 @@
#include <QApplication>
#include <QTranslator>
#include <QVariant>
#include <QLocale>
#define TS_PREFIX "vlmc_"
......@@ -42,17 +43,25 @@ LanguageHelper::~LanguageHelper()
void
LanguageHelper::languageChanged( const QVariant &vLang )
{
QString lang = vLang.toString();
if ( !lang.isEmpty() )
languageChanged( vLang.toString() );
}
void
LanguageHelper::languageChanged( const QString &lang )
{
if ( m_translator != NULL )
{
if ( m_translator != NULL )
{
qApp->removeTranslator( m_translator );
delete m_translator;
m_translator = NULL;
}
m_translator = new QTranslator();
m_translator->load( TS_PREFIX + lang, ":/ts/" );
qApp->installTranslator( m_translator );
qApp->removeTranslator( m_translator );
delete m_translator;
m_translator = NULL;
}
m_translator = new QTranslator();
if ( lang.isEmpty() || lang == "default" )
m_translator->load( TS_PREFIX + QLocale::system().name(), ":/ts/" );
else
m_translator->load( TS_PREFIX + lang, ":/ts/" );
qApp->installTranslator( m_translator );
}
......@@ -34,15 +34,15 @@ class LanguageHelper : public QObject, public Singleton<LanguageHelper>
Q_OBJECT
Q_DISABLE_COPY( LanguageHelper );
public slots:
void languageChanged( const QVariant& lang );
private:
LanguageHelper();
~LanguageHelper();
QTranslator *m_translator;
friend class Singleton<LanguageHelper>;
public slots:
void languageChanged( const QVariant &lang );
void languageChanged( const QString &lang );
private:
LanguageHelper();
~LanguageHelper();
QTranslator *m_translator;
friend class Singleton<LanguageHelper>;
};
#endif // LANGUAGEHELPER_H
......@@ -30,9 +30,10 @@
#include "MainWindow.h"
#include "project/GuiProjectManager.h"
#include "IntroDialog.h"
#include "LanguageHelper.h"
#include <QApplication>
#include <QTranslator>
#include <QSettings>
#include <QFile>
#include <QColor>
#include <QPalette>
......@@ -53,9 +54,9 @@ VLMCmain( int argc, char **argv )
app.setOrganizationDomain( "vlmc.org" );
app.setApplicationVersion( PROJECT_VERSION );
QTranslator appTranslator;
appTranslator.load( "vlmc_" + QLocale::system().name(), ":/ts/" );
app.installTranslator( &appTranslator );
QSettings s;
LanguageHelper::getInstance()->languageChanged(
s.value( "general/VLMCLang", "default" ) );
#ifdef Q_OS_WIN
......
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