From 7bf7416b660dcc1ec10b429756ee573d9fd1bbb2 Mon Sep 17 00:00:00 2001 From: spacy51 Date: Sun, 10 Feb 2008 12:35:36 +0000 Subject: [PATCH] Qt: ADDED spanish translation ADDED switch to enabled/disable translation git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@363 a31d4220-a93d-0410-bf67-fe4944624d44 --- lang/german.ts | 79 ++++++++++++------ lang/spanish.ts | 156 ++++++++++++++++++++++++++++++++++++ project/qmake/vba-m.pro | 1 + project/vc2008/vba-m.vcproj | 4 + src/qt/MainWnd.cpp | 87 +++++++++++++++++--- src/qt/MainWnd.h | 19 +++-- 6 files changed, 302 insertions(+), 44 deletions(-) create mode 100644 lang/spanish.ts diff --git a/lang/german.ts b/lang/german.ts index f38c17bb..d26b443b 100644 --- a/lang/german.ts +++ b/lang/german.ts @@ -1,6 +1,5 @@ - @default @@ -62,124 +61,154 @@ MainWnd - + VBA-M - + &File &Datei - + &Settings &Einstellungen - + &Tools &Werkzeuge - + &Help &Hilfe - + About &OpenGL... Über &OpenGL... - + About &VBA-M... Über &VBA-M... - + About &Qt... Über &Qt... - + This program is licensed under terms of the GNU General Public License. Dieses Programm ist unter den Bedingungen der GNU General Public License lizenziert. - + OpenGL version 2.1 is present. OpenGL Version 2.1 ist verfügbar. - + OpenGL version 2.0 is present. OpenGL Version 2.0 ist verfügbar. - + OpenGL version 1.5 is present. OpenGL Version 1.5 ist verfügbar. - + OpenGL version 1.4 is present. OpenGL Version 1.4 ist verfügbar. - + OpenGL version 1.3 is present. OpenGL Version 1.3 ist verfügbar. - + OpenGL version 1.2 is present. OpenGL Version 1.2 ist verfügbar. - + OpenGL version 1.1 is present. OpenGL Version 1.1 ist verfügbar. - + OpenGL is NOT available! OpenGL ist NICHT verfügbar! - + About VBA-M Über VBA-M - + About OpenGL Über OpenGL Select translation... - Übersetzung auswählen... + Übersetzung auswählen... Select translation - Übersetzung auswählen + Übersetzung auswählen Translation files (*.qm) - Übersetzungsdateien (*.qm) + Übersetzungsdateien (*.qm) - + .qm - + Exit Beenden + + + Select language... + Sprache auswählen... + + + + Select language + Sprache auswählen + + + + Language files (*.qm) + Sprachdateien (*.qm) + + + + Error! + Fehler! + + + + Language file can not be loaded! + Sprachdatei kann nicht geladen werden! + + + + Enable translation + Übersetzung aktivieren + diff --git a/lang/spanish.ts b/lang/spanish.ts new file mode 100644 index 00000000..ee0e3bd0 --- /dev/null +++ b/lang/spanish.ts @@ -0,0 +1,156 @@ + + + + MainWnd + + + VBA-M + VBA-M + + + + &File + &Archivo + + + + Exit + Salir + + + + &Settings + &Ajustes + + + + Select translation... + Seleccione traducción... + + + + &Tools + &Herramientas + + + + &Help + &Ayuda + + + + About &VBA-M... + Sobre &VBA-M... + + + + About &OpenGL... + Sobre &OpenGL... + + + + About &Qt... + Sobre &Qt... + + + + Select translation + Seleccione traducción + + + + Translation files (*.qm) + Archivos de traducción (*.qm) + + + + .qm + .qm + + + + About VBA-M + Sobre VBA-M + + + + This program is licensed under terms of the GNU General Public License. + Este programa se licencia bajo los términos de la Licencia Pública General GNU. + + + + OpenGL version 2.1 is present. + OpenGL versión 2.1 está presente. + + + + OpenGL version 2.0 is present. + OpenGL versión 2.0 está presente. + + + + OpenGL version 1.5 is present. + OpenGL versión 1.5 está presente. + + + + OpenGL version 1.4 is present. + OpenGL versión 1.4 está presente. + + + + OpenGL version 1.3 is present. + OpenGL versión 1.3 está presente. + + + + OpenGL version 1.2 is present. + OpenGL versión 1.2 está presente. + + + + OpenGL version 1.1 is present. + OpenGL versión 1.1 está presente. + + + + OpenGL is NOT available! + ¡OpenGL no está disponible! + + + + About OpenGL + Sobre OpenGL + + + + Select language... + Seleccione traducción... + + + + Select language + Seleccione traducción + + + + Language files (*.qm) + Archivos de traducción (*.qm) + + + + Error! + + + + + Language file can not be loaded! + + + + + Enable translation + + + + diff --git a/project/qmake/vba-m.pro b/project/qmake/vba-m.pro index 2a043a43..dc1a28c5 100644 --- a/project/qmake/vba-m.pro +++ b/project/qmake/vba-m.pro @@ -15,3 +15,4 @@ HEADERS += ../../src/qt/glwidget.h SOURCES += ../../src/qt/glwidget.cpp TRANSLATIONS += ../../lang/german.ts +TRANSLATIONS += ../../lang/spanish.ts diff --git a/project/vc2008/vba-m.vcproj b/project/vc2008/vba-m.vcproj index 67ff82d2..df09f706 100644 --- a/project/vc2008/vba-m.vcproj +++ b/project/vc2008/vba-m.vcproj @@ -106,6 +106,10 @@ RelativePath="..\..\lang\german.ts" > + + isEnabled(); // memorize state + checked = enableTranslationAct->isChecked(); + delete enableTranslationAct; + enableTranslationAct = 0; + } else { + enabled = false; + checked = false; + } + enableTranslationAct = new QAction( tr( "Enable translation" ), this ); + enableTranslationAct->setEnabled( enabled ); + enableTranslationAct->setCheckable( true ); + enableTranslationAct->setChecked( checked ); + connect( enableTranslationAct, SIGNAL( toggled( bool ) ), this, SLOT( enableTranslation( bool ) ) ); +} + void MainWnd::createMenus() { if( fileMenu ) { @@ -63,17 +85,22 @@ void MainWnd::createMenus() helpMenu = 0; } + // File menu fileMenu = menuBar()->addMenu( tr( "&File" ) ); fileMenu->addAction( tr( "Exit" ), this, SLOT( close() ) ); + // Settings menu settingsMenu = menuBar()->addMenu( tr( "&Settings" ) ); - settingsMenu->addAction( tr( "Select translation..." ), this, SLOT( selectTranslation() ) ); + settingsMenu->addAction( tr( "Select language..." ), this, SLOT( selectLanguage() ) ); + settingsMenu->addAction( enableTranslationAct ); + // Tools menu toolsMenu = menuBar()->addMenu( tr( "&Tools" ) ); + // Help menu helpMenu = menuBar()->addMenu( tr( "&Help" ) ); @@ -95,31 +122,67 @@ bool MainWnd::createDisplay() return false; } -void MainWnd::selectTranslation() +bool MainWnd::selectLanguage() { QString file = QFileDialog::getOpenFileName( this, - tr( "Select translation" ), + tr( "Select language" ), "lang", - tr( "Translation files (*.qm)" ) ); + tr( "Language files (*.qm)" ) ); - if( file.isNull() ) return; - if( !file.endsWith( tr( ".qm" ), Qt::CaseInsensitive ) ) return; + if( file.isNull() ) return false; - // load translation + bool ret = loadTranslation( file ); + ret &= enableTranslation( true ); + + if( ret == false ) { + QMessageBox::critical( this, tr( "Error!" ), tr( "Language file can not be loaded!" ) ); + } + return ret; +} + +bool MainWnd::loadTranslation( QString file ) +{ + if( !file.endsWith( tr( ".qm" ), Qt::CaseInsensitive ) ) return false; + + // remove current translation + enableTranslation( false ); if( *translator != 0 ) { - theApp->removeTranslator( *translator ); delete *translator; *translator = 0; } + file.chop( 3 ); // remove file extension ".qm" + + // load new translation *translator = new QTranslator(); - (*translator)->load( file ); - theApp->installTranslator( *translator ); + bool ret = (*translator)->load( file ); + enableTranslationAct->setEnabled( ret ); + return ret; +} + +bool MainWnd::enableTranslation( bool enable ) +{ + if( enable ) { + if( *translator != 0 ) { + theApp->installTranslator( *translator ); + enableTranslationAct->setChecked( true ); + } else { + return false; + } + } else { + if( *translator != 0 ) { + theApp->removeTranslator( *translator ); + } else { + return false; + } + } // apply translation - createMenus(); // the user might have to restart the application to apply changes completely + createActions(); + createMenus(); + return true; } void MainWnd::showAbout() diff --git a/src/qt/MainWnd.h b/src/qt/MainWnd.h index 1117e58d..6573c36c 100644 --- a/src/qt/MainWnd.h +++ b/src/qt/MainWnd.h @@ -29,23 +29,28 @@ public: MainWnd::MainWnd( QWidget *parent = 0, QApplication *app = 0, QTranslator **trans = 0 ); MainWnd::~MainWnd(); +public slots: + bool loadTranslation( QString file ); + private: + void createActions(); void createMenus(); bool createDisplay(); -private slots: - void selectTranslation(); - void showAbout(); - void showAboutOpenGL(); - void showAboutQt(); - -private: QApplication *theApp; QTranslator **translator; QMenu *fileMenu; QMenu *settingsMenu; + QAction *enableTranslationAct; QMenu *toolsMenu; QMenu *helpMenu; + +private slots: + bool selectLanguage(); + bool enableTranslation( bool enable ); + void showAbout(); + void showAboutOpenGL(); + void showAboutQt(); }; #endif // #ifndef MAINWND_H