diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-11-08 12:25:30 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-11-08 14:46:29 (GMT) |
commit | 27e77b7ceeeffe9227b5b96fdd63e3433e0eb63e (patch) | |
tree | 5f28fc510bd4649a8a86fd1cb9b5a39927369a7f /src/script/api/qscriptengine.cpp | |
parent | d48a324d6670b14348d546db6a739ee138dab1e2 (diff) | |
download | Qt-27e77b7ceeeffe9227b5b96fdd63e3433e0eb63e.zip Qt-27e77b7ceeeffe9227b5b96fdd63e3433e0eb63e.tar.gz Qt-27e77b7ceeeffe9227b5b96fdd63e3433e0eb63e.tar.bz2 |
Make qsTr() work with Unicode (non-Latin-1) strings
Converting the source string/context/comment to Latin-1 is very
broken, since JS strings are UTF-16.
The strings should be converted to UTF-8, which should also be
the default encoding for qsTranslate().
Effectively, this bug meant that only Latin-1 characters could
be used in source strings; the translations themselves could
have non-Latin-1 characters. But there was data loss in the
case where you passed a source string for which no translation
was found (since the Latin-1-ized string would be returned).
Task-number: QTBUG-14989
Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'src/script/api/qscriptengine.cpp')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 2d5e5f4..69abcad 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -808,7 +808,7 @@ JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState *exec, JSC::JSObje JSC::UString comment; if (args.size() > 2) comment = args.at(2).toString(exec); - QCoreApplication::Encoding encoding = QCoreApplication::CodecForTr; + QCoreApplication::Encoding encoding = QCoreApplication::UnicodeUTF8; if (args.size() > 3) { JSC::UString encStr = args.at(3).toString(exec); if (encStr == "CodecForTr") @@ -824,9 +824,9 @@ JSC::JSValue JSC_HOST_CALL functionQsTranslate(JSC::ExecState *exec, JSC::JSObje #endif JSC::UString result; #ifndef QT_NO_QOBJECT - result = QCoreApplication::translate(QScript::convertToLatin1(context).constData(), - QScript::convertToLatin1(text).constData(), - QScript::convertToLatin1(comment).constData(), + result = QCoreApplication::translate(context.UTF8String().c_str(), + text.UTF8String().c_str(), + comment.UTF8String().c_str(), encoding, n); #else result = text; @@ -878,10 +878,10 @@ JSC::JSValue JSC_HOST_CALL functionQsTr(JSC::ExecState *exec, JSC::JSObject*, JS #endif JSC::UString result; #ifndef QT_NO_QOBJECT - result = QCoreApplication::translate(QScript::convertToLatin1(context).constData(), - QScript::convertToLatin1(text).constData(), - QScript::convertToLatin1(comment).constData(), - QCoreApplication::CodecForTr, n); + result = QCoreApplication::translate(context.UTF8String().c_str(), + text.UTF8String().c_str(), + comment.UTF8String().c_str(), + QCoreApplication::UnicodeUTF8, n); #else result = text; #endif @@ -907,7 +907,7 @@ JSC::JSValue JSC_HOST_CALL functionQsTrId(JSC::ExecState *exec, JSC::JSObject*, int n = -1; if (args.size() > 1) n = args.at(1).toInt32(exec); - return JSC::jsString(exec, qtTrId(QScript::convertToLatin1(id).constData(), n)); + return JSC::jsString(exec, qtTrId(id.UTF8String().c_str(), n)); } JSC::JSValue JSC_HOST_CALL functionQsTrIdNoOp(JSC::ExecState *, JSC::JSObject*, JSC::JSValue, const JSC::ArgList &args) |