aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compileddata.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-03-06 16:19:42 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-11 18:31:21 +0100
commit914b72418b7e766026f2679254fcee93fc920866 (patch)
tree202634bd203c830ddc7eeb7dab1d071ca506b8a3 /src/qml/compiler/qv4compileddata.cpp
parentaf7ba8a6194b83fe7380b8d4ae027e2f04e21f17 (diff)
Add support for resolving translation bindings at compile time
Simple calls to qsTr and qsTrId are detected at type compile time and reduced to a special Translation and TranslationById binding type, which avoids allocating a QML binding at type instantiation type just to perform a translation. Change-Id: I61e4f2db2a8092b5e6870e174b832d9c20cd62b5 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler/qv4compileddata.cpp')
-rw-r--r--src/qml/compiler/qv4compileddata.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index 0ddc75488c..38c84140d3 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -46,6 +46,7 @@
#include <private/qv4objectproto_p.h>
#include <private/qv4lookup_p.h>
#include <private/qv4regexpobject_p.h>
+#include <QCoreApplication>
#include <algorithm>
@@ -190,6 +191,22 @@ QString Binding::valueAsString(const Unit *unit) const
return QString::number(value.d);
case Type_Invalid:
return QString();
+ case Type_TranslationById: {
+ QByteArray id = unit->stringAt(stringIndex).toUtf8();
+ return qtTrId(id.constData(), value.translationData.number);
+ }
+ case Type_Translation: {
+ // This code must match that in the qsTr() implementation
+ const QString &path = unit->stringAt(unit->sourceFileIndex);
+ int lastSlash = path.lastIndexOf(QLatin1Char('/'));
+ QString context = (lastSlash > -1) ? path.mid(lastSlash + 1, path.length()-lastSlash-5) :
+ QString();
+ QByteArray contextUtf8 = context.toUtf8();
+ QByteArray comment = unit->stringAt(value.translationData.commentIndex).toUtf8();
+ QByteArray text = unit->stringAt(stringIndex).toUtf8();
+ return QCoreApplication::translate(contextUtf8.constData(), text.constData(),
+ comment.constData(), value.translationData.number);
+ }
default:
break;
}