[vlmc-devel] LanguageHelper.cpp: Translate Qt's dialogs built-in buttons
Rohit Yadav
git at videolan.org
Fri Jul 22 23:36:23 CEST 2011
vlmc | branch: master | Rohit Yadav <rohityadav89 at gmail.com> | Sat Jul 23 03:21:11 2011 +0530| [3005174ac349de744627302a28e17ebaf97fb6d4] | committer: Rohit Yadav
LanguageHelper.cpp: Translate Qt's dialogs built-in buttons
Fixes Bug #39, uses Qt's translation files in QLibraryInfo::TranslationsPath
to translate Qt's built-in UI strinfs in dialogs, message boxes etc
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=3005174ac349de744627302a28e17ebaf97fb6d4
---
src/Gui/LanguageHelper.cpp | 24 ++++++++++++++++++++----
src/Gui/LanguageHelper.h | 1 +
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/Gui/LanguageHelper.cpp b/src/Gui/LanguageHelper.cpp
index d57eeff..faad41c 100644
--- a/src/Gui/LanguageHelper.cpp
+++ b/src/Gui/LanguageHelper.cpp
@@ -23,13 +23,14 @@
#include "LanguageHelper.h"
#include <QApplication>
+#include <QLibraryInfo>
+#include <QLocale>
#include <QTranslator>
#include <QVariant>
-#include <QLocale>
#define TS_PREFIX "vlmc_"
-LanguageHelper::LanguageHelper() : m_translator( NULL )
+LanguageHelper::LanguageHelper() : m_translator( NULL ), m_qtTranslator( NULL )
{
connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( deleteLater() ) );
}
@@ -38,6 +39,8 @@ LanguageHelper::~LanguageHelper()
{
if ( m_translator )
delete m_translator;
+ if ( m_qtTranslator )
+ delete m_qtTranslator;
}
void
@@ -49,19 +52,32 @@ LanguageHelper::languageChanged( const QVariant &vLang )
void
LanguageHelper::languageChanged( const QString &lang )
{
- if ( m_translator != NULL )
+ if ( m_translator != NULL || m_qtTranslator != NULL )
{
qApp->removeTranslator( m_translator );
+ qApp->removeTranslator( m_qtTranslator );
delete m_translator;
+ delete m_qtTranslator;
m_translator = NULL;
+ m_qtTranslator = NULL;
}
m_translator = new QTranslator();
+ m_qtTranslator = new QTranslator();
if ( lang.isEmpty() || lang == "default" )
+ {
m_translator->load( TS_PREFIX + QLocale::system().name(), ":/ts/" );
+ m_qtTranslator->load( "qt_" + QLocale::system().name(),
+ QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
+ }
else
+ {
m_translator->load( TS_PREFIX + lang, ":/ts/" );
+ m_qtTranslator->load( "qt_" + lang,
+ QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
+ }
- qApp->installTranslator( m_translator );
+ qApp->installTranslator( m_translator ); // For translating VLMC UI strings
+ qApp->installTranslator( m_qtTranslator ); // For translating Qt's dialog buttons etc.
}
diff --git a/src/Gui/LanguageHelper.h b/src/Gui/LanguageHelper.h
index 677fbe2..79e6236 100644
--- a/src/Gui/LanguageHelper.h
+++ b/src/Gui/LanguageHelper.h
@@ -41,6 +41,7 @@ private:
LanguageHelper();
~LanguageHelper();
QTranslator *m_translator;
+ QTranslator *m_qtTranslator;
friend class Singleton<LanguageHelper>;
};
More information about the Vlmc-devel
mailing list