summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2021-01-12 16:28:06 +0200
committerKatja Marttila <katja.marttila@qt.io>2021-01-14 22:39:09 +0200
commit4d9620977c81401f88212196b1d1a1094fc19699 (patch)
tree31ca12ea43344f07818ac4e5febec8ab283f5cdf
parentc9eb521f4520d5624ad83ed3a54705169049ad1c (diff)
Fix translating from component script
Translate using QCoreApplication::translate instead of QObject::tr. Removed the use of obsolete installTranslatorFunctions() function. Task-number: QTIFW-392 Change-Id: Icdd67efb6889acd26d63297fb89945c3431c881c Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
-rw-r--r--doc/installerfw.qdoc7
-rw-r--r--examples/translations/packages/com.vendor.product/meta/installscript.qs2
-rw-r--r--src/libs/installer/scriptengine.cpp7
-rw-r--r--src/libs/installer/scriptengine_p.h21
4 files changed, 3 insertions, 34 deletions
diff --git a/doc/installerfw.qdoc b/doc/installerfw.qdoc
index d5335d585..ebc1e2044 100644
--- a/doc/installerfw.qdoc
+++ b/doc/installerfw.qdoc
@@ -703,16 +703,11 @@
</Translations>
\endcode
- Use the \c {qsTr()} function for literal text within scripts. Additionally,
+ Use the \c {qsTranslate()} function for literal text within scripts. Additionally,
you can add the \c Component.prototype.retranslateUi method to the script.
It is called when the language of the installer changes and the translation
file is loaded.
- 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. 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.ts file to replace any text in the installer with a custom English
version.
diff --git a/examples/translations/packages/com.vendor.product/meta/installscript.qs b/examples/translations/packages/com.vendor.product/meta/installscript.qs
index 317fa5aa2..140d81533 100644
--- a/examples/translations/packages/com.vendor.product/meta/installscript.qs
+++ b/examples/translations/packages/com.vendor.product/meta/installscript.qs
@@ -55,6 +55,6 @@ Component.prototype.dynamicPageEntered = function ()
{
var pageWidget = gui.pageWidgetByObjectName("DynamicPage");
if (pageWidget != null) {
- pageWidget.m_pageLabel.text = qsTr("This is a dynamically created page.");
+ pageWidget.m_pageLabel.text = qsTranslate("installscript", "This is a dynamically created page.");
}
}
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp
index 4d062c9cb..ae5bed72c 100644
--- a/src/libs/installer/scriptengine.cpp
+++ b/src/libs/installer/scriptengine.cpp
@@ -372,6 +372,7 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) :
QObject(core),
m_guiProxy(new GuiProxy(this, this))
{
+ m_engine.installExtensions(QJSEngine::TranslationExtension);
QJSValue global = m_engine.globalObject();
global.setProperty(QLatin1String("console"), m_engine.newQObject(new ConsoleProxy));
global.setProperty(QLatin1String("QFileDialog"), m_engine.newQObject(new QFileDialogProxy(core)));
@@ -379,12 +380,6 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) :
global.setProperty(QLatin1String("InstallerProxy"), proxy);
global.setProperty(QLatin1String("print"), m_engine.newQObject(new ConsoleProxy)
.property(QLatin1String("log")));
-#if QT_VERSION < 0x050400
- global.setProperty(QLatin1String("qsTr"), m_engine.newQObject(new QCoreApplicationProxy)
- .property(QStringLiteral("qsTr")));
-#else
- m_engine.installTranslatorFunctions();
-#endif
global.setProperty(QLatin1String("systemInfo"), m_engine.newQObject(new SystemInfo));
global.setProperty(QLatin1String("QInstaller"), generateQInstallerObject());
diff --git a/src/libs/installer/scriptengine_p.h b/src/libs/installer/scriptengine_p.h
index bf8240d98..c5f04c0dc 100644
--- a/src/libs/installer/scriptengine_p.h
+++ b/src/libs/installer/scriptengine_p.h
@@ -125,24 +125,6 @@ private:
ScriptEngine *m_engine;
};
-#if QT_VERSION < 0x050400
-class QCoreApplicationProxy : public QObject
-{
- Q_OBJECT
- Q_DISABLE_COPY(QCoreApplicationProxy)
-
-public:
- QCoreApplicationProxy() {}
-
-public slots:
- QString qsTr(const QString &text = QString(), const QString &disambiguation = QString(), int n = -1) const
- {
- return QCoreApplication::translate(QCoreApplication::applicationName().toUtf8().constData(),
- text.toUtf8().constData(), disambiguation.toUtf8().constData(), n);
- }
-};
-#endif
-
class GuiProxy : public QObject
{
Q_OBJECT
@@ -198,8 +180,5 @@ Q_DECLARE_METATYPE(QInstaller::ConsoleProxy*)
Q_DECLARE_METATYPE(QInstaller::InstallerProxy*)
Q_DECLARE_METATYPE(QInstaller::QFileDialogProxy*)
Q_DECLARE_METATYPE(QInstaller::QDesktopServicesProxy*)
-#if QT_VERSION < 0x050400
-Q_DECLARE_METATYPE(QInstaller::QCoreApplicationProxy*)
-#endif
#endif // SCRIPTENGINE_H