diff options
author | Niels Weber <niels.weber@digia.com> | 2015-01-29 12:29:09 +0100 |
---|---|---|
committer | Niels Weber <niels.weber@theqtcompany.com> | 2015-02-09 10:06:46 +0000 |
commit | 52ebff797da4a29f61459fd6d183d2e07498c591 (patch) | |
tree | afe58065d5ad36faee01a9f5268c57fa006e9a3e /examples | |
parent | 04dcfb68cb7e2c3995f0b66b1bbd926b1864819b (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>
Diffstat (limited to 'examples')
14 files changed, 303 insertions, 0 deletions
diff --git a/examples/doc/images/qtifw-examples-translations.png b/examples/doc/images/qtifw-examples-translations.png Binary files differnew file mode 100644 index 000000000..1025c7c0c --- /dev/null +++ b/examples/doc/images/qtifw-examples-translations.png 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 |