[rkward-cvs] [rkward/work/i18n_split_lists] /: First part of splitting .rkh translation units on <ul>, <li>, and friends: Split units on extraction.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Sat Feb 7 19:18:16 UTC 2015


Git commit 72530a9a7aa5631eb2b45cf8938d7f1bf23583e6 by Thomas Friedrichsmeier.
Committed on 07/02/2015 at 19:17.
Pushed by tfry into branch 'work/i18n_split_lists'.

First part of splitting .rkh translation units on <ul>, <li>, and friends: Split units on extraction.

M  +2    -1    rkward/misc/xmlhelper.cpp
M  +15   -2    scripts/update_plugin_messages.py

http://commits.kde.org/rkward/72530a9a7aa5631eb2b45cf8938d7f1bf23583e6

diff --git a/rkward/misc/xmlhelper.cpp b/rkward/misc/xmlhelper.cpp
index 78edcf3..fc8cd42 100644
--- a/rkward/misc/xmlhelper.cpp
+++ b/rkward/misc/xmlhelper.cpp
@@ -326,7 +326,8 @@ QString translateChunk (const QString &chunk, const QString &context, bool add_p
 
 	for (int i = 0; i < paras.count (); ++i) {
 		QString para = paras[i].simplified ();
-		if (!para.isEmpty ()) {
+		if (para.isEmpty ()) ret.append (QChar (' '));
+		else {
 			if (!ret.isEmpty ()) ret.append ("\n");
 			// Oh, crap. Fix up after some differences between python message extraction and qt's.
 			para.replace ("<li> <", "<li><");
diff --git a/scripts/update_plugin_messages.py b/scripts/update_plugin_messages.py
index 18cb068..4e469a5 100755
--- a/scripts/update_plugin_messages.py
+++ b/scripts/update_plugin_messages.py
@@ -45,6 +45,8 @@ MSGFMT = os.getenv ('MSGFMT', "msgfmt --check")
 
 # list of tag-names the content of which to extract in full (including, possibly, HTML-tags, within)
 text_containers = ['section', 'text', 'related', 'title', 'summary', 'usage', 'technical', 'setting']
+# (HTML)-elements on which to split translation units within a text_container
+text_splitting_elements = ['p', 'ul', 'ol', 'li']
 # Elements that refer to a different (labelled) element by id
 referring_elements = ['setting', 'caption']
 # Map of elements to attributes to extract, and default context info
@@ -170,9 +172,19 @@ def normalize (text):
   
 # get everything inside the element as text. Might include further xml tags.
 def getFullText (element):
+  childnodes = element.childNodes
+  ## Skip over anything containing only a <link href="rkward://"/> and nothing else; a somewhat important special case ("Related"-section)
+  ## NOTE: The second attribute, here, is the LINE_DUMMY_ATTR , hence checking for cn.attributes.length == 2
+  if (childnodes.length == 1):
+    cn = childnodes.item (0)
+    if (not cn.hasChildNodes()) and (cn.nodeType == cn.ELEMENT_NODE) and (cn.tagName == "link") and (cn.attributes.length == 2) and (cn.getAttribute ("href").startswith ("rkward://")):
+      return ""
+
   rc = []
-  for cn in element.childNodes:
-    if cn.nodeType != cn.COMMENT_NODE:
+  for cn in childnodes:
+    if (cn.nodeType == cn.ELEMENT_NODE) and (cn.tagName in text_splitting_elements):
+      rc.append ("\n\n" + getFullText (cn) + "\n\n")
+    elif cn.nodeType != cn.COMMENT_NODE:
       rc.append(stripLineDummy (cn.toxml ("utf-8")))
   return ''.join (rc).strip ().replace ("&", "&")
 
@@ -229,6 +241,7 @@ def handleNode (node):
     elif (node.tagName in text_containers):
       textchunks = getFullText (node).split ("\n\n")
       for chunk in textchunks:
+        chunk = chunk.strip ()
         if (chunk != ""):
           outfile.write (getI18nComment (node))
           writeouti18n ("i18n (" + quote (normalize (chunk)) + ");")


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
rkward-cvs mailing list
rkward-cvs at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rkward-cvs


More information about the rkward-tracker mailing list