qsTranslate shouldn't require an encoding argument
authorLars Knoll <lars.knoll@nokia.com>
Sun, 6 May 2012 21:14:36 +0000 (23:14 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 8 May 2012 22:56:16 +0000 (00:56 +0200)
The encoding is anyway utf-8 in all case, so we can just
as well get rid of the argument. Support the old syntax
for backwards compatibility, but issue a qWarning when it's
being used.

The new syntax simply removes the encoding as 4th argument.

Change-Id: Ib34aec58997a4f026440385e8ed763ef953674d8
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/qml/qml/v8/qqmlbuiltinfunctions.cpp

index 761676d..26ecc93 100644 (file)
@@ -1190,8 +1190,6 @@ v8::Handle<v8::Value> qsTranslate(const v8::Arguments &args)
         V8THROW_ERROR("qsTranslate(): second argument (text) must be a string");
     if ((args.Length() > 2) && !args[2]->IsString())
         V8THROW_ERROR("qsTranslate(): third argument (comment) must be a string");
-    if ((args.Length() > 3) && !args[3]->IsString())
-        V8THROW_ERROR("qsTranslate(): fourth argument (encoding) must be a string");
 
     QV8Engine *v8engine = V8ENGINE();
     QString context = v8engine->toString(args[0]);
@@ -1199,25 +1197,20 @@ v8::Handle<v8::Value> qsTranslate(const v8::Arguments &args)
     QString comment;
     if (args.Length() > 2) comment = v8engine->toString(args[2]);
 
-    QCoreApplication::Encoding encoding = QCoreApplication::UnicodeUTF8;
-    if (args.Length() > 3) {
-        QString encStr = v8engine->toString(args[3]);
-        if (encStr == QLatin1String("UnicodeUTF8")) {
-            encoding = QCoreApplication::UnicodeUTF8;
-        } else {
-            QString msg = QString::fromLatin1("qsTranslate(): invalid encoding '%0'").arg(encStr);
-            V8THROW_ERROR((uint16_t *)msg.constData());
-        }
+    int i = 3;
+    if (args.Length() > i && args[i]->IsString()) {
+        qWarning("qsTranslate(): specifying the encoding as fourth argument is deprecated");
+        ++i;
     }
 
     int n = -1;
-    if (args.Length() > 4)
-        n = args[4]->Int32Value();
+    if (args.Length() > i)
+        n = args[i]->Int32Value();
 
     QString result = QCoreApplication::translate(context.toUtf8().constData(),
                                                  text.toUtf8().constData(),
                                                  comment.toUtf8().constData(),
-                                                 encoding, n);
+                                                 QCoreApplication::UnicodeUTF8, n);
 
     return v8engine->toString(result);
 }