From 52ebff797da4a29f61459fd6d183d2e07498c591 Mon Sep 17 00:00:00 2001 From: Niels Weber Date: Thu, 29 Jan 2015 12:29:09 +0100 Subject: 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 --- doc/config/ifw.qdocconf | 2 +- doc/installerfw.qdoc | 17 ++++- .../doc/images/qtifw-examples-translations.png | Bin 0 -> 18683 bytes examples/doc/translations.qdoc | 80 +++++++++++++++++++++ examples/translations/README | 20 ++++++ examples/translations/config/config.xml | 9 +++ .../com.vendor.product/data/installcontent.txt | 2 + .../packages/com.vendor.product/meta/de.ts | 22 ++++++ .../com.vendor.product/meta/installscript.qs | 66 +++++++++++++++++ .../packages/com.vendor.product/meta/license.txt | 1 + .../com.vendor.product/meta/license_de.txt | 1 + .../com.vendor.product/meta/license_pl.txt | 1 + .../packages/com.vendor.product/meta/package.xml | 19 +++++ .../packages/com.vendor.product/meta/page.ui | 44 ++++++++++++ .../packages/com.vendor.product/meta/pl.ts | 25 +++++++ examples/translations/translations.pro | 13 ++++ src/libs/installer/component.cpp | 12 +++- 17 files changed, 329 insertions(+), 5 deletions(-) create mode 100644 examples/doc/images/qtifw-examples-translations.png create mode 100644 examples/doc/translations.qdoc create mode 100644 examples/translations/README create mode 100644 examples/translations/config/config.xml create mode 100644 examples/translations/packages/com.vendor.product/data/installcontent.txt create mode 100644 examples/translations/packages/com.vendor.product/meta/de.ts create mode 100644 examples/translations/packages/com.vendor.product/meta/installscript.qs create mode 100644 examples/translations/packages/com.vendor.product/meta/license.txt create mode 100644 examples/translations/packages/com.vendor.product/meta/license_de.txt create mode 100644 examples/translations/packages/com.vendor.product/meta/license_pl.txt create mode 100644 examples/translations/packages/com.vendor.product/meta/package.xml create mode 100644 examples/translations/packages/com.vendor.product/meta/page.ui create mode 100644 examples/translations/packages/com.vendor.product/meta/pl.ts create mode 100644 examples/translations/translations.pro 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 + + de.qm + + \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 Binary files /dev/null and b/examples/doc/images/qtifw-examples-translations.png 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 .ts + \endcode + + Replace 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 .ts + \endcode + + + \include installerfw-examples-configuring.qdocinc + + \quotefile translations/config/config.xml + + \include installerfw-examples-packaging.qdocinc + + \list + \li The \c element is set to \c true to preselect the + component in the installer. + \li The \c + + page.ui + + + de.qm + pl.qm + + 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 @@ + + + Page + + + + 0 + 0 + 400 + 300 + + + + Translations Example + + + + + + QFrame::Box + + + Qt::AlignCenter + + + + + + + QFrame::Box + + + This is some text. + + + Qt::AlignCenter + + + + + + + + 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 @@ + + + + + Page + + + Translations Example + Przykład obrazujący przekład na inny język + + + + This is some text. + To jest pewien tekst. + + + + installscript + + + This is a dynamically created page. + Jest to strona utworzona dynamicznie. + + + 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