summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiels Weber <niels.weber@digia.com>2015-01-29 12:29:09 +0100
committerNiels Weber <niels.weber@theqtcompany.com>2015-02-09 10:06:46 +0000
commit52ebff797da4a29f61459fd6d183d2e07498c591 (patch)
treeafe58065d5ad36faee01a9f5268c57fa006e9a3e
parent04dcfb68cb7e2c3995f0b66b1bbd926b1864819b (diff)
Add a translation example
Add an example showing how the translation of components works. Also document this. Make translated license files work again. Task-number: QTIFW-469 Change-Id: I3c13ecc9941b09370d0713b19b2683b42454c43c Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
-rw-r--r--doc/config/ifw.qdocconf2
-rw-r--r--doc/installerfw.qdoc17
-rw-r--r--examples/doc/images/qtifw-examples-translations.pngbin0 -> 18683 bytes
-rw-r--r--examples/doc/translations.qdoc80
-rw-r--r--examples/translations/README20
-rw-r--r--examples/translations/config/config.xml9
-rw-r--r--examples/translations/packages/com.vendor.product/data/installcontent.txt2
-rw-r--r--examples/translations/packages/com.vendor.product/meta/de.ts22
-rw-r--r--examples/translations/packages/com.vendor.product/meta/installscript.qs66
-rw-r--r--examples/translations/packages/com.vendor.product/meta/license.txt1
-rw-r--r--examples/translations/packages/com.vendor.product/meta/license_de.txt1
-rw-r--r--examples/translations/packages/com.vendor.product/meta/license_pl.txt1
-rw-r--r--examples/translations/packages/com.vendor.product/meta/package.xml19
-rw-r--r--examples/translations/packages/com.vendor.product/meta/page.ui44
-rw-r--r--examples/translations/packages/com.vendor.product/meta/pl.ts25
-rw-r--r--examples/translations/translations.pro13
-rw-r--r--src/libs/installer/component.cpp12
17 files changed, 329 insertions, 5 deletions
diff --git a/doc/config/ifw.qdocconf b/doc/config/ifw.qdocconf
index d2ceafd73..f399ca872 100644
--- a/doc/config/ifw.qdocconf
+++ b/doc/config/ifw.qdocconf
@@ -18,7 +18,7 @@ exampledirs = $SRCDIR ../../examples
headers.fileextensions = "*.h"
sources.fileextensions = "*.qdoc *.qdocinc *.cpp"
-examples.fileextensions = "*.js *.qs *.txt *.xml *.ui"
+examples.fileextensions = "*.js *.qs *.txt *.xml *.ui *.ts"
examples.imageextensions = "*.png"
indexes += $QT_INSTALL_DOCS/qtcore/qtcore.index \
diff --git a/doc/installerfw.qdoc b/doc/installerfw.qdoc
index 14f07fa37..b209b03a4 100644
--- a/doc/installerfw.qdoc
+++ b/doc/installerfw.qdoc
@@ -453,7 +453,17 @@
interfaces, create QTranslator files that the installation system loads
along with the component. The installer loads the translation file that
matches the current system locale. For example, if the system locale is
- German, the de_de.qm file is loaded.
+ German, the de.qm file is loaded. In addition, a localized \c license_de.txt
+ is shown instead of the default \c license.txt if it is found.
+
+ Translations need to be added to the \c package.xml file to be activated for
+ a component:
+
+ \code
+ <Translations>
+ <Translation>de.qm</Translation>
+ </Translations>
+ \endcode
Use the \c {qsTr()} function for literal text within scripts. Additionally,
you can add the \c Component.prototype.retranslateUi method to the script.
@@ -462,10 +472,11 @@
The context being used for translation is the basename of the script file
when using \c qsTr or the class name of the UI file when translating a user
- interface.
+ interface. For example, if the script file is called \c installscript.qs, the
+ context will be installscript.
\note The translation system can also be used to customize the UI. Use e.g.
- an \c en_en.ts file to replace any text in the installer with a custom English
+ an \c en.ts file to replace any text in the installer with a custom English
version.
*/
diff --git a/examples/doc/images/qtifw-examples-translations.png b/examples/doc/images/qtifw-examples-translations.png
new file mode 100644
index 000000000..1025c7c0c
--- /dev/null
+++ b/examples/doc/images/qtifw-examples-translations.png
Binary files differ
diff --git a/examples/doc/translations.qdoc b/examples/doc/translations.qdoc
new file mode 100644
index 000000000..5ef579778
--- /dev/null
+++ b/examples/doc/translations.qdoc
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example translations
+ \ingroup qtifwexamples
+ \title Translation Example
+
+ \brief Using translations to localize installer pages and licenses.
+
+ \image qtifw-examples-translations.png
+
+ \e{Translations} illustrates how to use translations to localize the output
+ of component scripts and component UI files into another language. It also shows
+ how to select the license according to the system language.
+
+ To add a new language, you first need to create a translation source (TS) file for
+ the package that contains all the translatable strings. Run the following command in
+ the package's meta directory:
+
+ \code
+ lupdate installscript.qs page.ui -ts <language>.ts
+ \endcode
+
+ Replace <language> with the two letter lowercase code for the language you want to
+ translate to. After finishing translating you need to use lrelease on that
+ TS file to generate the binary Qt messages (QM) file. Do not forget to include
+ that in the package.xml as shown below. Run the following command in
+ the package's meta directory:
+
+ \code
+ lrelase <language>.ts
+ \endcode
+
+
+ \include installerfw-examples-configuring.qdocinc
+
+ \quotefile translations/config/config.xml
+
+ \include installerfw-examples-packaging.qdocinc
+
+ \list
+ \li The \c <Default> element is set to \c true to preselect the
+ component in the installer.
+ \li The \c <Script> element specifies the file name of the JavaScript
+ file that is loaded to perform operations.
+ \li The \c <License> element specifies the file name of the license file
+ that is shown when this component is selected for installation.
+ \li The \c <Translations> element specifies the file name of the QM
+ file containing translations for this compontent's UI and script files.
+ \endlist
+
+ \quotefile translations/packages/com.vendor.product/meta/package.xml
+
+ \include installerfw-examples-generating.qdocinc
+*/
diff --git a/examples/translations/README b/examples/translations/README
new file mode 100644
index 000000000..13fb2b685
--- /dev/null
+++ b/examples/translations/README
@@ -0,0 +1,20 @@
+Shows how to translate the installer UI.
+
+You have to call lrelease on the included .ts file before building the installer.
+
+Generate installer with
+
+binarycreator --offline-only -c config/config.xml -p packages installer
+
+You can now run the installer in German.
+
+Linux:
+
+LANG=de ./installer
+
+Windows:
+
+set LANG=de
+installer.exe
+
+On OS X you need to adapt the system settings to set German as preferred language, and then start the installer.
diff --git a/examples/translations/config/config.xml b/examples/translations/config/config.xml
new file mode 100644
index 000000000..bacf61cce
--- /dev/null
+++ b/examples/translations/config/config.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Installer>
+ <Name>Translations Example</Name>
+ <Version>1.0.0</Version>
+ <Title>Package Translations Example</Title>
+ <Publisher>Qt Project</Publisher>
+ <StartMenuDir>Qt Installer Framework Examples</StartMenuDir>
+ <TargetDir>@HomeDir@/IfwExample</TargetDir>
+</Installer>
diff --git a/examples/translations/packages/com.vendor.product/data/installcontent.txt b/examples/translations/packages/com.vendor.product/data/installcontent.txt
new file mode 100644
index 000000000..f40001983
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/data/installcontent.txt
@@ -0,0 +1,2 @@
+This file will be installed into the target directory....
+
diff --git a/examples/translations/packages/com.vendor.product/meta/de.ts b/examples/translations/packages/com.vendor.product/meta/de.ts
new file mode 100644
index 000000000..dd6000354
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/meta/de.ts
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="de_DE">
+<context>
+ <name>Page</name>
+ <message>
+ <source>Translations Example</source>
+ <translation>Beispiel für Übersetzungen</translation>
+ </message>
+ <message>
+ <source>This is some text.</source>
+ <translation>Dies ist ein Text.</translation>
+ </message>
+</context>
+<context>
+ <name>installscript</name>
+ <message>
+ <source>This is a dynamically created page.</source>
+ <translation>Diese Seite wurde dynamisch erzeugt.</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/translations/packages/com.vendor.product/meta/installscript.qs b/examples/translations/packages/com.vendor.product/meta/installscript.qs
new file mode 100644
index 000000000..cb4db4cd5
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/meta/installscript.qs
@@ -0,0 +1,66 @@
+/**************************************************************************
+**
+** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+function Component()
+{
+ // constructor
+ component.loaded.connect(this, Component.prototype.loaded);
+ installer.addWizardPage(component, "Page", QInstaller.TargetDirectory)
+}
+
+Component.prototype.createOperations = function()
+{
+ try {
+ // call the base create operations function
+ component.createOperations();
+ } catch (e) {
+ print(e);
+ }
+}
+
+Component.prototype.loaded = function ()
+{
+ var page = gui.pageByObjectName("DynamicPage");
+ if (page != null) {
+ page.entered.connect(Component.prototype.dynamicPageEntered);
+ }
+}
+
+Component.prototype.dynamicPageEntered = function ()
+{
+ var pageWidget = gui.pageWidgetByObjectName("DynamicPage");
+ if (pageWidget != null) {
+ pageWidget.m_pageLabel.text = qsTr("This is a dynamically created page.");
+ }
+}
diff --git a/examples/translations/packages/com.vendor.product/meta/license.txt b/examples/translations/packages/com.vendor.product/meta/license.txt
new file mode 100644
index 000000000..61a94dce7
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/meta/license.txt
@@ -0,0 +1 @@
+The fantastic license, have you heard of the Beer Public License Agreement yet?
diff --git a/examples/translations/packages/com.vendor.product/meta/license_de.txt b/examples/translations/packages/com.vendor.product/meta/license_de.txt
new file mode 100644
index 000000000..1af6f50fa
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/meta/license_de.txt
@@ -0,0 +1 @@
+Lizenz auf deutsch.
diff --git a/examples/translations/packages/com.vendor.product/meta/license_pl.txt b/examples/translations/packages/com.vendor.product/meta/license_pl.txt
new file mode 100644
index 000000000..685636262
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/meta/license_pl.txt
@@ -0,0 +1 @@
+Licencja po polsku.
diff --git a/examples/translations/packages/com.vendor.product/meta/package.xml b/examples/translations/packages/com.vendor.product/meta/package.xml
new file mode 100644
index 000000000..1bdf34970
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/meta/package.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Package>
+ <DisplayName>The root component</DisplayName>
+ <Description>This component contains a license and translations to German.</Description>
+ <Version>0.5.0-1</Version>
+ <ReleaseDate>2015-01-29</ReleaseDate>
+ <Licenses>
+ <License name="Beer Public License Agreement" file="license.txt" />
+ </Licenses>
+ <Default>true</Default>
+ <Script>installscript.qs</Script>
+ <UserInterfaces>
+ <UserInterface>page.ui</UserInterface>
+ </UserInterfaces>
+ <Translations>
+ <Translation>de.qm</Translation>
+ <Translation>pl.qm</Translation>
+ </Translations>
+</Package>
diff --git a/examples/translations/packages/com.vendor.product/meta/page.ui b/examples/translations/packages/com.vendor.product/meta/page.ui
new file mode 100644
index 000000000..0b5a2a68d
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/meta/page.ui
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Page</class>
+ <widget class="QWidget" name="Page">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Translations Example</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="m_pageLabel">
+ <property name="frameShape">
+ <enum>QFrame::Box</enum>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="m_pageLabel2">
+ <property name="frameShape">
+ <enum>QFrame::Box</enum>
+ </property>
+ <property name="text">
+ <string>This is some text.</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/translations/packages/com.vendor.product/meta/pl.ts b/examples/translations/packages/com.vendor.product/meta/pl.ts
new file mode 100644
index 000000000..7f7649b51
--- /dev/null
+++ b/examples/translations/packages/com.vendor.product/meta/pl.ts
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="pl_PL">
+<context>
+ <name>Page</name>
+ <message>
+ <location filename="page.ui" line="14"/>
+ <source>Translations Example</source>
+ <translation>Przykład obrazujący przekład na inny język</translation>
+ </message>
+ <message>
+ <location filename="page.ui" line="36"/>
+ <source>This is some text.</source>
+ <translation>To jest pewien tekst.</translation>
+ </message>
+</context>
+<context>
+ <name>installscript</name>
+ <message>
+ <location filename="installscript.qs" line="64"/>
+ <source>This is a dynamically created page.</source>
+ <translation>Jest to strona utworzona dynamicznie.</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/translations/translations.pro b/examples/translations/translations.pro
new file mode 100644
index 000000000..415df49d5
--- /dev/null
+++ b/examples/translations/translations.pro
@@ -0,0 +1,13 @@
+TEMPLATE = aux
+
+INSTALLER = installer
+
+INPUT = $$PWD/config/config.xml $$PWD/packages
+example.input = INPUT
+example.output = $$INSTALLER
+example.commands = ../../bin/binarycreator -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT}
+example.CONFIG += target_predeps no_link combine
+
+QMAKE_EXTRA_COMPILERS += example
+
+OTHER_FILES = README
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp
index 22b7143b0..be5d7e1b0 100644
--- a/src/libs/installer/component.cpp
+++ b/src/libs/installer/component.cpp
@@ -284,6 +284,10 @@ void Component::loadDataFromPackage(const LocalPackage &package)
setValue(scCurrentState, scInstalled);
}
+/*!
+ Sets variables according to the values set in the package.xml file of \a package.
+ Also loads UI files, licenses and translations if they are referenced in the package.xml.
+*/
void Component::loadDataFromPackage(const Package &package)
{
Q_ASSERT(&package);
@@ -603,9 +607,15 @@ void Component::loadLicenses(const QString &directory, const QHash<QString, QVar
QFileInfo fileInfo(fileName);
QFile file(QString::fromLatin1("%1%2_%3.%4").arg(directory, fileInfo.baseName(),
QLocale().name().toLower(), fileInfo.completeSuffix()));
+ if (!file.exists()) {
+ file.setFileName(QString::fromLatin1("%1%2_%3.%4").arg(directory, fileInfo.baseName(),
+ QLocale().name().left(2), fileInfo.completeSuffix()));
+ }
+
if (!file.open(QIODevice::ReadOnly)) {
// No translated license, use untranslated file
- qDebug("Unable to open translated license file. Using untranslated fallback.");
+ qDebug().nospace() << "Unable to open translated license file" << file.fileName()
+ << ". Using untranslated fallback.";
file.setFileName(directory + fileName);
if (!file.open(QIODevice::ReadOnly)) {
throw Error(tr("Could not open the requested license file '%1'. Error: %2").arg(fileName,