[rkward-cvs] [rkward/releases/0.6.3] rkward/misc: First part of splitting .rkh translation units on <ul>, <li>, and friends: Prepare the lookup.

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


Git commit 87318a522d7a45d1ccca3eac8edd9d90b85b148a by Thomas Friedrichsmeier.
Committed on 07/02/2015 at 12:46.
Pushed by tfry into branch 'releases/0.6.3'.

First part of splitting .rkh translation units on <ul>, <li>, and friends: Prepare the lookup.

M  +43   -20   rkward/misc/xmlhelper.cpp

http://commits.kde.org/rkward/87318a522d7a45d1ccca3eac8edd9d90b85b148a

diff --git a/rkward/misc/xmlhelper.cpp b/rkward/misc/xmlhelper.cpp
index d6fd815..78edcf3 100644
--- a/rkward/misc/xmlhelper.cpp
+++ b/rkward/misc/xmlhelper.cpp
@@ -319,27 +319,11 @@ bool XMLHelper::getBoolAttribute (const QDomElement &element, const QString &nam
 	return def;
 }
 
-QString XMLHelper::i18nElementText (const QDomElement &element, bool with_paragraphs, int debug_level) const {
-	RK_TRACE (XML);
-
+QString translateChunk (const QString &chunk, const QString &context, bool add_paragraphs, const RKMessageCatalog *catalog) {
+	// if (!with_paragraphs), text should better not contain double newlines. We treat all the same, though, just as the message extraction script does.
+	QStringList paras = chunk.split ("\n\n");
 	QString ret;
-	QTextStream stream (&ret);
 
-	if (!element.isNull()) {
-		QTextStream stream (&ret, QIODevice::WriteOnly);
-		for (QDomNode node = element.firstChild (); !node.isNull (); node = node.nextSibling ()) {
-			node.save (stream, 0);
-		}
-	} else {
-		displayError (&element, i18n ("Trying to retrieve contents of invalid element"), debug_level);
-		return QString ();
-	}
-
-	QString context = element.attribute ("i18n_context", QString ());
-
-	// if (!with_paragraphs), text should better not contain double newlines. We treat all the same, though, just as the message extraction script does.
-	QStringList paras = ret.split ("\n\n");
-	ret.clear ();
 	for (int i = 0; i < paras.count (); ++i) {
 		QString para = paras[i].simplified ();
 		if (!para.isEmpty ()) {
@@ -350,7 +334,7 @@ QString XMLHelper::i18nElementText (const QDomElement &element, bool with_paragr
 			para.replace ("> </li>", "></li>");
 			para.replace ("&", "&");
 			QString text = context.isNull () ? catalog->translate (para) : catalog->translate (context, para);
-			if (with_paragraphs) ret += "<p>" + text + "</p>";
+			if (add_paragraphs) ret += "<p>" + text + "</p>";
 			else ret += text;
 		}
 	}
@@ -358,6 +342,45 @@ QString XMLHelper::i18nElementText (const QDomElement &element, bool with_paragr
 	return ret;
 }
 
+QString XMLHelper::i18nElementText (const QDomElement &element, bool with_paragraphs, int debug_level) const {
+	RK_TRACE (XML);
+
+	if (element.isNull ()) {
+		displayError (&element, i18n ("Trying to retrieve contents of invalid element"), debug_level);
+		return QString ();
+	}
+
+	QString ret;
+	QString context = element.attribute ("i18n_context", QString ());
+	QString buffer;
+	QTextStream stream (&buffer, QIODevice::WriteOnly);
+	for (QDomNode node = element.firstChild (); !node.isNull (); node = node.nextSibling ()) {
+		QDomElement e = node.toElement ();
+		if (!e.isNull ()) {
+			if (e.tagName () == QLatin1String ("ul") || e.tagName () == QLatin1String ("ol") || e.tagName () == QLatin1String ("li") || e.tagName () == QLatin1String ("p")) { // split translation units on these elements
+				// split before
+				ret.append (translateChunk (buffer, context, with_paragraphs, catalog));
+				buffer.clear ();
+
+				// serialize the tag with all its attributes but not the children.
+				e.cloneNode (false).save (stream, 0);   // will write: <TAG[ attributes]/>
+				buffer = buffer.left (buffer.lastIndexOf ('/')) + QChar ('>');
+				buffer.append (i18nElementText (e, false, debug_level));
+				buffer.append ("</" + e.tagName () + QChar ('>'));
+
+				// split after
+				ret.append (buffer);
+				buffer.clear ();
+				continue;
+			}
+		}
+		node.save (stream, 0);
+	}
+	ret.append (translateChunk (buffer, context, with_paragraphs, catalog));
+
+	return ret;
+}
+
 void XMLHelper::displayError (const QDomNode *in_node, const QString &message, int debug_level, int message_level) const {
 	RK_TRACE (XML);
 


------------------------------------------------------------------------------
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