[vlmc-devel] commit: Use the LanguageHelper class for loading the locale. ( Ludovic Fauvet )

git at videolan.org git at videolan.org
Tue Apr 13 16:17:31 CEST 2010


vlmc | branch: master | Ludovic Fauvet <etix at l0cal.com> | Tue Apr 13 16:10:51 2010 +0200| [414a282d60deb912c2e9201c0022a71a60d7aa9a] | committer: Ludovic Fauvet 

Use the LanguageHelper class for loading the locale.

Also avoid code duplication.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=414a282d60deb912c2e9201c0022a71a60d7aa9a
---

 src/Gui/LanguageHelper.cpp |   31 ++++++++++++++++++++-----------
 src/Gui/LanguageHelper.h   |   18 +++++++++---------
 src/Main/guimain.cpp       |    9 +++++----
 3 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/src/Gui/LanguageHelper.cpp b/src/Gui/LanguageHelper.cpp
index 2d8c393..d57eeff 100644
--- a/src/Gui/LanguageHelper.cpp
+++ b/src/Gui/LanguageHelper.cpp
@@ -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 );
 }
diff --git a/src/Gui/LanguageHelper.h b/src/Gui/LanguageHelper.h
index 5024206..677fbe2 100644
--- a/src/Gui/LanguageHelper.h
+++ b/src/Gui/LanguageHelper.h
@@ -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
diff --git a/src/Main/guimain.cpp b/src/Main/guimain.cpp
index d2ba557..2bb72ce 100644
--- a/src/Main/guimain.cpp
+++ b/src/Main/guimain.cpp
@@ -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
 



More information about the Vlmc-devel mailing list