[rkward-cvs] SF.net SVN: rkward-code:[4989] trunk/rkward

tfry at users.sf.net tfry at users.sf.net
Tue Nov 4 21:06:46 UTC 2014


Revision: 4989
          http://sourceforge.net/p/rkward/code/4989
Author:   tfry
Date:     2014-11-04 21:06:45 +0000 (Tue, 04 Nov 2014)
Log Message:
-----------
Properly deal with the various quoting chars in js message extraction

Modified Paths:
--------------
    trunk/rkward/rkward/plugins/testing/test1.js
    trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
    trunk/rkward/scripts/extract_plugin_messages.py

Modified: trunk/rkward/rkward/plugins/testing/test1.js
===================================================================
--- trunk/rkward/rkward/plugins/testing/test1.js	2014-11-04 13:30:10 UTC (rev 4988)
+++ trunk/rkward/rkward/plugins/testing/test1.js	2014-11-04 21:06:45 UTC (rev 4989)
@@ -15,6 +15,7 @@
 
 	echo ('### i18n tests below ###\n');
 	echo ('print (' + i18n ("This is an i18n text") + ')\n');
+	echo ('print (' + i18n ('This is a single quoted i18n text, with a variety of quoting chars (\' " \` \" `), and a %1 inside:', 1) + ')\n');
 	echo ('# A comment: ' + i18nc ("Dummy context", noquote ("This is a non-auto-quoted i18n'ed text with context")) + '\n');
 	for (var i = 10; i > 0; --i) {
 		echo ('print (' + i18np ("There was one green bottle standing on the %2", "There were %1 green bottles standing on the %2", i, i18n (noquote ("wall"))) + ')\n');

Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp	2014-11-04 13:30:10 UTC (rev 4988)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp	2014-11-04 21:06:45 UTC (rev 4989)
@@ -329,6 +329,13 @@
 	bool loadCommonScript (QScriptEngine* engine, QString scriptfile) {
 		RK_TRACE (PHP);
 
+		// NOTE: QScriptProgram cannot be evaluated concurrently in several threads (see https://bugreports.qt-project.org/browse/QTBUG-29246).
+		// Neither would our QMap caching logic work in concurrent threads. Thus the mutex. This clearly has the drawback that QScript evaluation threads
+		// may be waiting for each other during initialization. However, we assume that
+		// - Typically only few such threads are running
+		// - Responsiveness (i.e. UI startup speed), not throughput is the main goal, here.
+		// - The important script engines are those running in the UI thread (and thus necessarily sequentially). As long as these are initialized before
+		//   the other threads, they will clearly profit from pre-compiling
 		QMutexLocker ml (&compiled_includes_mutex);
 		if (!compiled_includes.contains (scriptfile)) {
 			RK_DEBUG (PHP, DL_DEBUG, "Compiling common script file %s", qPrintable (scriptfile));

Modified: trunk/rkward/scripts/extract_plugin_messages.py
===================================================================
--- trunk/rkward/scripts/extract_plugin_messages.py	2014-11-04 13:30:10 UTC (rev 4988)
+++ trunk/rkward/scripts/extract_plugin_messages.py	2014-11-04 21:06:45 UTC (rev 4989)
@@ -253,13 +253,13 @@
     while (not self.startswith (string)):
       if (self.atEof ()):
         break
-      if (self.startswith ('\\')):
-        self.advance (2)
-        continue
       if (self.buf[self.nchar] in ['"', '\'', '`']):
         ochar = self.buf[self.nchar]
-        if (self.advance ()):
-          self.seekUntil (ochar)
+        while (self.advance ()):
+          if (self.startswith ('\\')):
+            self.advance ()	# skip next char
+          elif (self.startswith (ochar)):
+            break
       elif (self.startswith ("/*")):
         self.comment = self.seekUntil ("*/")
       elif (self.startswith ("//")):
@@ -278,6 +278,36 @@
 def handleJSChunk (buf, filename, offset, caption):
   global outfile
 
+  # Convert single quoted and backtick quoted strings in the input chunk to double quotes (so xgettext can work in C-style).
+  def normalizeQuotes (chunk):
+    pos = 0
+    current_quote_symbol = ""
+    output = ""
+    strip_closing_parentheses = 0
+    while (pos < len (chunk)):
+      c = chunk[pos]
+      if c == "\\":
+        nc = chunk[pos+1]
+        if ((nc != current_quote_symbol) or (nc == '"')):
+          output += c
+        output += nc
+        pos += 1
+      elif c in ['"', '\'', '`']:
+        if (current_quote_symbol == ""):
+          current_quote_symbol = c
+          output += '"'
+        elif current_quote_symbol == c:
+          current_quote_symbol = ""
+          output += '"'
+        elif c == '"':
+          output += '\\\"'
+        else:
+          output += c
+      else:
+        output += c
+      pos += 1
+    return output
+
   jsbuf = JSParseBuffer (buf)
   while (True):
     call = ""
@@ -286,7 +316,6 @@
       break
     for candidate in ["i18n", "i18nc", "i18np", "i18ncp"]:
       if (jsbuf.isAtFunctionCall (candidate)):
-        print ("found " + candidate)
         call = candidate
         break
     if (call == ""):
@@ -314,7 +343,7 @@
     if (offset >= 0):
       text += ":" + str (offset + line + 1)
     text += "\ni18n: ectx: (" + caption + ") */\n"
-    text += call + parameters + ";\n"
+    text += call + normalizeQuotes (parameters) + ";\n"
     outfile.write (text)
 
 # When we encounter a "file"-attribute, we generally dive right into parsing that file, i.e. we do depth first





More information about the rkward-tracker mailing list