aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-07-27 15:30:40 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-28 11:27:26 +0200
commitaa2d36a3d7405c3130b27b41b0e3941ca466f3cd (patch)
tree7b828aec3ffcce11a66bc0425b0c338855821864
parentff7867460cbaf18fc09717b111df7abb344f5957 (diff)
Fix translation context for QML files.
Use the base file name as done in QtQuick 1, rather than using the entire path. This also fixes QTBUG-17255 for QtQuick 2. Change-Id: Ia27f6539f82d6caf6e7060b89ff1996d42ffb9cb Reviewed-on: http://codereview.qt.nokia.com/2246 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
-rw-r--r--src/declarative/qml/v8/qv8engine.cpp5
-rw-r--r--tests/auto/declarative/declarative.pro1
-rw-r--r--tests/auto/declarative/qdeclarativetranslation/data/translation.qrc6
-rw-r--r--tests/auto/declarative/qdeclarativetranslation/qdeclarativetranslation.pro1
-rw-r--r--tests/auto/declarative/qdeclarativetranslation/tst_qdeclarativetranslation.cpp26
5 files changed, 37 insertions, 2 deletions
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp
index b8a1bc41e2..2dd52b0ac3 100644
--- a/src/declarative/qml/v8/qv8engine.cpp
+++ b/src/declarative/qml/v8/qv8engine.cpp
@@ -1587,7 +1587,10 @@ v8::Handle<v8::Value> QV8Engine::qsTr(const v8::Arguments &args)
QV8Engine *v8engine = V8ENGINE();
QDeclarativeContextData *ctxt = v8engine->callingContext();
- QString context = ctxt->url.toString();
+ QString path = ctxt->url.toString();
+ int lastSlash = path.lastIndexOf(QLatin1Char('/'));
+ QString context = (lastSlash > -1) ? path.mid(lastSlash + 1, path.length()-lastSlash-5) : QString();
+
QString text = v8engine->toString(args[0]);
QString comment;
if (args.Length() > 1)
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 183c920ece..43a2a682de 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/declarative/declarative.pro
@@ -19,6 +19,7 @@ PUBLICTESTS += \
qdeclarativemoduleplugin \
qdeclarativepixmapcache \
qdeclarativeqt \
+ qdeclarativetranslation \
qdeclarativexmlhttprequest
PRIVATETESTS += \
diff --git a/tests/auto/declarative/qdeclarativetranslation/data/translation.qrc b/tests/auto/declarative/qdeclarativetranslation/data/translation.qrc
new file mode 100644
index 0000000000..2e2d0a0497
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetranslation/data/translation.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>translation.qml</file>
+ <file>qml_fr.qm</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/declarative/qdeclarativetranslation/qdeclarativetranslation.pro b/tests/auto/declarative/qdeclarativetranslation/qdeclarativetranslation.pro
index c970a0c70e..b6f0df2fbc 100644
--- a/tests/auto/declarative/qdeclarativetranslation/qdeclarativetranslation.pro
+++ b/tests/auto/declarative/qdeclarativetranslation/qdeclarativetranslation.pro
@@ -3,6 +3,7 @@ contains(QT_CONFIG,declarative): QT += declarative
macx:CONFIG -= app_bundle
SOURCES += tst_qdeclarativetranslation.cpp
+RESOURCES += data/translation.qrc
symbian: {
importFiles.files = data
diff --git a/tests/auto/declarative/qdeclarativetranslation/tst_qdeclarativetranslation.cpp b/tests/auto/declarative/qdeclarativetranslation/tst_qdeclarativetranslation.cpp
index 5b88b548c9..109b98bdc4 100644
--- a/tests/auto/declarative/qdeclarativetranslation/tst_qdeclarativetranslation.cpp
+++ b/tests/auto/declarative/qdeclarativetranslation/tst_qdeclarativetranslation.cpp
@@ -43,7 +43,6 @@
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include <QTranslator>
-#include <QDebug>
#ifdef Q_OS_SYMBIAN
// In Symbian OS test data is located in applications private dir
@@ -59,6 +58,7 @@ public:
private slots:
void translation();
void idTranslation();
+ void translationInQrc();
};
inline QUrl TEST_FILE(const QString &filename)
@@ -108,6 +108,30 @@ void tst_qdeclarativetranslation::idTranslation()
delete object;
}
+void tst_qdeclarativetranslation::translationInQrc()
+{
+ QTranslator translator;
+ translator.load(":/qml_fr.qm");
+ QApplication::installTranslator(&translator);
+
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("qrc:/translation.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("basic").toString(), QLatin1String("bonjour"));
+ QCOMPARE(object->property("basic2").toString(), QLatin1String("au revoir"));
+ QCOMPARE(object->property("disambiguation").toString(), QLatin1String("salut"));
+ QCOMPARE(object->property("disambiguation2").toString(), QString::fromUtf8("\xc3\xa0 plus tard"));
+ QCOMPARE(object->property("noop").toString(), QLatin1String("bonjour"));
+ QCOMPARE(object->property("noop2").toString(), QLatin1String("au revoir"));
+ QCOMPARE(object->property("singular").toString(), QLatin1String("1 canard"));
+ QCOMPARE(object->property("plural").toString(), QLatin1String("2 canards"));
+
+ QApplication::removeTranslator(&translator);
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativetranslation)
#include "tst_qdeclarativetranslation.moc"