changeset 420:16b6d5686835

Switch to resource based loading of translations
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 16 Apr 2014 17:00:59 +0000
parents 413b29f6758f
children 7edfc9b9b360
files ui/CMakeLists.txt ui/administrator.cpp ui/l10n/administrator.qrc.in ui/l10n/administrator.ts ui/l10n/administrator_de_DE.ts
diffstat 5 files changed, 243 insertions(+), 215 deletions(-) [+]
line wrap: on
line diff
--- a/ui/CMakeLists.txt	Wed Apr 16 16:05:46 2014 +0000
+++ b/ui/CMakeLists.txt	Wed Apr 16 17:00:59 2014 +0000
@@ -112,11 +112,21 @@
 qt5_add_resources(ADMINSTRATOR_SOURCES_WITH_RESOURCES ${ADMINSTRATOR_RESOURCES})
 
 if(Qt5LinguistTools_FOUND)
+   # Include translation as a resource
+   # This works in the source directory to enable the rcc dependencies to be found
+   # and it also updates the currently available localization.
+   # This would probably be better placed in a macro
+   configure_file(l10n/administrator.qrc.in administrator.qrc)
+   qt5_add_resources(ADMINISTRATOR_L10N ${CMAKE_CURRENT_BINARY_DIR}/administrator.qrc)
    qt5_create_translation(ADMINISTRATOR_TRANSLATION ${ADMINSTRATOR_SOURCES_WITH_RESOURCES}
-      ${CMAKE_CURRENT_SOURCE_DIR}/l10n/administrator.ts)
-  add_executable(administrator ${ADMINSTRATOR_SOURCES_WITH_RESOURCES} ${ADMINISTRATOR_TRANSLATION})
+      ${CMAKE_CURRENT_SOURCE_DIR}/l10n/administrator_de_DE.ts)
+   add_executable(administrator ${ADMINSTRATOR_SOURCES_WITH_RESOURCES}
+      ${ADMINISTRATOR_L10N}
+      ${ADMINISTRATOR_TRANSLATION}
+      )
 else()
-   message (STATUS "WARNING: Could not find qt linguist tools. Translation will not be included.")
+  message (STATUS "WARNING: Could not find qt linguist tools. Translation will not be included.")
+  add_executable(administrator ${ADMINSTRATOR_SOURCES_WITH_RESOURCES})
 endif()
 
 target_link_libraries(administrator Qt5::Widgets
--- a/ui/administrator.cpp	Wed Apr 16 16:05:46 2014 +0000
+++ b/ui/administrator.cpp	Wed Apr 16 17:00:59 2014 +0000
@@ -11,6 +11,8 @@
 #include <QtPlugin>
 #include <QMessageBox>
 #include <QSettings>
+#include <QTranslator>
+#include <QDebug>
 
 #ifndef VERSION
 #define VERSION "0.0.1"
@@ -41,6 +43,17 @@
     QApplication::setApplicationVersion(QString::fromLatin1(VERSION));
     QSettings::setDefaultFormat(QSettings::IniFormat);
 
+    QTranslator translator;
+    if (QLocale::system().name() == "C") {
+        /* Useful for testing / development as the primary target is german */
+        translator.load(":/l10n/administrator_de_DE");
+    } else {
+        translator.load(":/l10n/administrator_" + QLocale::system().name());
+        qDebug() << "Loading translations for: " << "administrator_" +
+            QLocale::system().name();
+    }
+    app.installTranslator(&translator);
+
     AdministratorWindow adminWin;
     adminWin.show();
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/l10n/administrator.qrc.in	Wed Apr 16 17:00:59 2014 +0000
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/l10n">
+    <file alias="administrator_de_DE.qm">@CMAKE_CURRENT_BINARY_DIR@/administrator_de_DE.qm</file>
+</qresource>
+</RCC>
--- a/ui/l10n/administrator.ts	Wed Apr 16 16:05:46 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,212 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.1" language="de">
-<context>
-    <name>AdministratorWindow</name>
-    <message>
-        <location filename="../administratorwindow.cpp" line="49"/>
-        <source>Menu</source>
-        <translation>MenĂ¼</translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="51"/>
-        <source>Create Installer</source>
-        <translation>Installationspaket erstellen</translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="52"/>
-        <source>Settings</source>
-        <translation>Einstellungen</translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="54"/>
-        <source>Help</source>
-        <translation>Hilfe</translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="55"/>
-        <source>About</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="57"/>
-        <source>Quit</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="79"/>
-        <source>Managed Certificates</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="102"/>
-        <source>Administrator Application</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="113"/>
-        <source>Save</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="115"/>
-        <source>Load</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="117"/>
-        <source>Add</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="119"/>
-        <source>Remove</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="144"/>
-        <source>Select certificate file</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../administratorwindow.cpp" line="165"/>
-        <source>Select certificate</source>
-        <translation type="unfinished"></translation>
-    </message>
-</context>
-<context>
-    <name>CertificateTabelModel</name>
-    <message>
-        <location filename="../certificatetablemodel.cpp" line="16"/>
-        <source>Subject CN</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../certificatetablemodel.cpp" line="17"/>
-        <source>Subject O</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../certificatetablemodel.cpp" line="18"/>
-        <source>Issuer CN</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../certificatetablemodel.cpp" line="19"/>
-        <source>Issuer O</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../certificatetablemodel.cpp" line="20"/>
-        <source>valid from</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../certificatetablemodel.cpp" line="21"/>
-        <source>valid to</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../certificatetablemodel.cpp" line="22"/>
-        <source>SHA1 Fingerprint</source>
-        <translation type="unfinished"></translation>
-    </message>
-</context>
-<context>
-    <name>CertificateTableDelegate</name>
-    <message>
-        <location filename="../certificatetabledelegate.cpp" line="51"/>
-        <source>add</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../certificatetabledelegate.cpp" line="54"/>
-        <source>remove</source>
-        <translation type="unfinished"></translation>
-    </message>
-</context>
-<context>
-    <name>CreateCertListDialog</name>
-    <message>
-        <location filename="../createcertlistdialog.cpp" line="21"/>
-        <source>adminstrator - Create signed certificate list</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../createcertlistdialog.cpp" line="35"/>
-        <source>Create a new, signed certificate list.
-</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../createcertlistdialog.cpp" line="63"/>
-        <source>Create List</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../createcertlistdialog.cpp" line="81"/>
-        <source>Select certificate</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../createcertlistdialog.cpp" line="88"/>
-        <source>Select target location</source>
-        <translation type="unfinished"></translation>
-    </message>
-</context>
-<context>
-    <name>CreateInstallerDialog</name>
-    <message>
-        <location filename="../createinstallerdialog.cpp" line="21"/>
-        <source>adminstrator - Create signed installer binary</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../createinstallerdialog.cpp" line="36"/>
-        <source>Create a new signed installer binary.
-</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../createinstallerdialog.cpp" line="75"/>
-        <source>Create Installer</source>
-        <translation type="unfinished">Installationspaket erstellen</translation>
-    </message>
-    <message>
-        <location filename="../createinstallerdialog.cpp" line="93"/>
-        <source>Select certificate</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../createinstallerdialog.cpp" line="100"/>
-        <source>Select source archive</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../createinstallerdialog.cpp" line="107"/>
-        <source>Select target location</source>
-        <translation type="unfinished"></translation>
-    </message>
-</context>
-<context>
-    <name>QObject</name>
-    <message>
-        <location filename="../certificate.cpp" line="75"/>
-        <source>Certificate:
-    &lt;bold&gt;%1&lt;/bold&gt;
-    %2, %3
-
-Serial number:
-%4
-Valid from: &lt;bold&gt;%5&lt;/bold&gt; to &lt;bold&gt;%6&lt;/bold&gt;
-
-Issued by: ..</source>
-        <translation type="unfinished"></translation>
-    </message>
-    <message>
-        <location filename="../certificate.cpp" line="129"/>
-        <source>Failed to parse certificate</source>
-        <translation type="unfinished"></translation>
-    </message>
-</context>
-</TS>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/l10n/administrator_de_DE.ts	Wed Apr 16 17:00:59 2014 +0000
@@ -0,0 +1,212 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="de">
+<context>
+    <name>AdministratorWindow</name>
+    <message>
+        <location filename="../administratorwindow.cpp" line="49"/>
+        <source>Menu</source>
+        <translation>MenĂ¼</translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="51"/>
+        <source>Create Installer</source>
+        <translation>Installationspaket erstellen</translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="52"/>
+        <source>Settings</source>
+        <translation>Einstellungen</translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="54"/>
+        <source>Help</source>
+        <translation>Hilfe</translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="55"/>
+        <source>About</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="57"/>
+        <source>Quit</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="79"/>
+        <source>Managed Certificates</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="102"/>
+        <source>Administrator Application</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="113"/>
+        <source>Save</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="115"/>
+        <source>Load</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="117"/>
+        <source>Add</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="119"/>
+        <source>Remove</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="144"/>
+        <source>Select certificate file</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../administratorwindow.cpp" line="165"/>
+        <source>Select certificate</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
+    <name>CertificateTabelModel</name>
+    <message>
+        <location filename="../certificatetablemodel.cpp" line="16"/>
+        <source>Subject CN</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../certificatetablemodel.cpp" line="17"/>
+        <source>Subject O</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../certificatetablemodel.cpp" line="18"/>
+        <source>Issuer CN</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../certificatetablemodel.cpp" line="19"/>
+        <source>Issuer O</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../certificatetablemodel.cpp" line="20"/>
+        <source>valid from</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../certificatetablemodel.cpp" line="21"/>
+        <source>valid to</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../certificatetablemodel.cpp" line="22"/>
+        <source>SHA1 Fingerprint</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
+    <name>CertificateTableDelegate</name>
+    <message>
+        <location filename="../certificatetabledelegate.cpp" line="51"/>
+        <source>add</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../certificatetabledelegate.cpp" line="54"/>
+        <source>remove</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
+    <name>CreateCertListDialog</name>
+    <message>
+        <location filename="../createcertlistdialog.cpp" line="21"/>
+        <source>adminstrator - Create signed certificate list</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createcertlistdialog.cpp" line="35"/>
+        <source>Create a new, signed certificate list.
+</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createcertlistdialog.cpp" line="63"/>
+        <source>Create List</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createcertlistdialog.cpp" line="81"/>
+        <source>Select certificate</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createcertlistdialog.cpp" line="88"/>
+        <source>Select target location</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
+    <name>CreateInstallerDialog</name>
+    <message>
+        <location filename="../createinstallerdialog.cpp" line="21"/>
+        <source>adminstrator - Create signed installer binary</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createinstallerdialog.cpp" line="36"/>
+        <source>Create a new signed installer binary.
+</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createinstallerdialog.cpp" line="75"/>
+        <source>Create Installer</source>
+        <translation type="unfinished">Installationspaket erstellen</translation>
+    </message>
+    <message>
+        <location filename="../createinstallerdialog.cpp" line="93"/>
+        <source>Select certificate</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createinstallerdialog.cpp" line="100"/>
+        <source>Select source archive</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../createinstallerdialog.cpp" line="107"/>
+        <source>Select target location</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
+    <name>QObject</name>
+    <message>
+        <location filename="../certificate.cpp" line="75"/>
+        <source>Certificate:
+    &lt;bold&gt;%1&lt;/bold&gt;
+    %2, %3
+
+Serial number:
+%4
+Valid from: &lt;bold&gt;%5&lt;/bold&gt; to &lt;bold&gt;%6&lt;/bold&gt;
+
+Issued by: ..</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="../certificate.cpp" line="129"/>
+        <source>Failed to parse certificate</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+</TS>

http://wald.intevation.org/projects/trustbridge/