aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/compiler/qv4compileddata.cpp2
-rw-r--r--tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp19
2 files changed, 19 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index 39f48f67f8..4b5d5dc96d 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -730,7 +730,7 @@ QString Binding::valueAsString(const CompilationUnit *unit) const
case Type_Translation: {
const TranslationData &translation = unit->unitData()->translations()[value.translationDataIndex];
// This code must match that in the qsTr() implementation
- const QString &path = unit->stringAt(unit->unitData()->sourceFileIndex);
+ const QString &path = unit->fileName();
int lastSlash = path.lastIndexOf(QLatin1Char('/'));
QStringRef context = (lastSlash > -1) ? path.midRef(lastSlash + 1, path.length() - lastSlash - 5)
: QStringRef();
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
index 6c399f6874..97ac466e94 100644
--- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
+++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
@@ -36,6 +36,7 @@
#include <QSysInfo>
#include <QLoggingCategory>
#include <private/qqmlcomponent_p.h>
+#include <qtranslator.h>
class tst_qmlcachegen: public QObject
{
@@ -169,11 +170,26 @@ void tst_qmlcachegen::loadGeneratedFile()
QVERIFY(unitData->flags & QV4::CompiledData::Unit::StaticData);
}
+class QTestTranslator : public QTranslator
+{
+public:
+ QString translate(const char *context, const char *sourceText, const char */*disambiguation*/, int /*n*/) const override
+ {
+ m_lastContext = QString::fromUtf8(context);
+ return QString::fromUtf8(sourceText).toUpper();
+ }
+ bool isEmpty() const override { return true; }
+ mutable QString m_lastContext;
+};
+
void tst_qmlcachegen::translationExpressionSupport()
{
QTemporaryDir tempDir;
QVERIFY(tempDir.isValid());
+ QTestTranslator translator;
+ qApp->installTranslator(&translator);
+
const auto writeTempFile = [&tempDir](const QString &fileName, const char *contents) {
QFile f(tempDir.path() + '/' + fileName);
const bool ok = f.open(QIODevice::WriteOnly | QIODevice::Truncate);
@@ -207,7 +223,8 @@ void tst_qmlcachegen::translationExpressionSupport()
CleanlyLoadingComponent component(&engine, QUrl::fromLocalFile(testFilePath));
QScopedPointer<QObject> obj(component.create());
QVERIFY(!obj.isNull());
- QCOMPARE(obj->property("text").toString(), QString("All Ok"));
+ QCOMPARE(obj->property("text").toString(), QString("ALL Ok"));
+ QCOMPARE(translator.m_lastContext, QStringLiteral("test"));
}
void tst_qmlcachegen::signalHandlerParameters()