summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-06-29 15:06:15 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-08-23 08:25:41 (GMT)
commitd1c482180352aeecabcc8d9f65ab3883175c75c3 (patch)
treed5ba94d6b69918d7942b0d7bb1cf853348317689 /src
parenta5867a413d14f307c0f20b7080840b15bd8743e4 (diff)
downloadQt-d1c482180352aeecabcc8d9f65ab3883175c75c3.zip
Qt-d1c482180352aeecabcc8d9f65ab3883175c75c3.tar.gz
Qt-d1c482180352aeecabcc8d9f65ab3883175c75c3.tar.bz2
Make qsTrId() / QT_TRID_NOOP() accessible from QtScript
QScriptEngine::installTranslatorFunctions() now installs wrapper functions for qsTrId and QT_TRID_NOOP (similar to the existing ones for tr() and translate()). Task-number: QTBUG-8454 Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'src')
-rw-r--r--src/script/api/qscriptengine.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 8560214..8347626 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -782,6 +782,8 @@ static JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState*, JSC::JSOb
static JSC::JSValue JSC_HOST_CALL functionQsTranslateNoOp(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
static JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
static JSC::JSValue JSC_HOST_CALL functionQsTrNoOp(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
+static JSC::JSValue JSC_HOST_CALL functionQsTrId(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
+static JSC::JSValue JSC_HOST_CALL functionQsTrIdNoOp(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
{
@@ -892,6 +894,28 @@ JSC::JSValue JSC_HOST_CALL functionQsTrNoOp(JSC::ExecState *, JSC::JSObject*, JS
return args.at(0);
}
+JSC::JSValue JSC_HOST_CALL functionQsTrId(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
+{
+ if (args.size() < 1)
+ return JSC::throwError(exec, JSC::GeneralError, "qsTrId() requires at least one argument");
+ if (!args.at(0).isString())
+ return JSC::throwError(exec, JSC::TypeError, "qsTrId(): first argument (id) must be a string");
+ if ((args.size() > 1) && !args.at(1).isNumber())
+ return JSC::throwError(exec, JSC::TypeError, "qsTrId(): second argument (n) must be a number");
+ JSC::UString id = args.at(0).toString(exec);
+ int n = -1;
+ if (args.size() > 1)
+ n = args.at(1).toInt32(exec);
+ return JSC::jsString(exec, qtTrId(QScript::convertToLatin1(id).constData(), n));
+}
+
+JSC::JSValue JSC_HOST_CALL functionQsTrIdNoOp(JSC::ExecState *, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args)
+{
+ if (args.size() < 1)
+ return JSC::jsUndefined();
+ return args.at(0);
+}
+
static JSC::JSValue JSC_HOST_CALL stringProtoFuncArg(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
JSC::JSValue JSC_HOST_CALL stringProtoFuncArg(JSC::ExecState *exec, JSC::JSObject*, JSC::JSValue thisObject, const JSC::ArgList &args)
@@ -3435,6 +3459,8 @@ void QScriptEngine::registerCustomType(int type, MarshalFunction mf,
\row \o QT_TR_NOOP() \o QT_TR_NOOP()
\row \o qsTranslate() \o QCoreApplication::translate()
\row \o QT_TRANSLATE_NOOP() \o QT_TRANSLATE_NOOP()
+ \row \o qsTrId() (since 4.7) \o qtTrId()
+ \row \o QT_TRID_NOOP() (since 4.7) \o QT_TRID_NOOP()
\endtable
\sa {Internationalization with Qt}
@@ -3453,6 +3479,8 @@ void QScriptEngine::installTranslatorFunctions(const QScriptValue &object)
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 2, JSC::Identifier(exec, "QT_TRANSLATE_NOOP"), QScript::functionQsTranslateNoOp));
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 3, JSC::Identifier(exec, "qsTr"), QScript::functionQsTr));
JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "QT_TR_NOOP"), QScript::functionQsTrNoOp));
+ JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "qsTrId"), QScript::functionQsTrId));
+ JSC::asObject(jscObject)->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "QT_TRID_NOOP"), QScript::functionQsTrIdNoOp));
glob->stringPrototype()->putDirectFunction(exec, new (exec)JSC::NativeFunctionWrapper(exec, glob->prototypeFunctionStructure(), 1, JSC::Identifier(exec, "arg"), QScript::stringProtoFuncArg));
}