[rkward-cvs] [rkward] rkward/windows: Fix i18n-lookup of messages that contain <link>-elements

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Fri Dec 5 13:45:54 UTC 2014


Git commit 83f198d223d302b68fb44580790b7a3f7a2d755d by Thomas Friedrichsmeier.
Committed on 05/12/2014 at 13:45.
Pushed by tfry into branch 'master'.

Fix i18n-lookup of messages that contain <link>-elements

M  +15   -8    rkward/windows/rkhtmlwindow.cpp

http://commits.kde.org/rkward/83f198d223d302b68fb44580790b7a3f7a2d755d

diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index 3e80d4a..43472ad 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -688,16 +688,23 @@ bool RKHTMLWindow::renderRKHelp (const KUrl &url) {
 QString RKHTMLWindow::renderHelpFragment (QDomElement &fragment, const XMLHelper *xml) {
 	RK_TRACE (APP);
 
-	// prepare all internal links
-	QDomNodeList link_nodes = fragment.elementsByTagName ("link");
-	for (int i=link_nodes.count (); i >= 0; --i) {
-		QDomElement element = link_nodes.item (i).toElement ();
-		if (element.isNull ()) continue;
+	QString ret = xml->i18nElementText (fragment, true, DL_WARNING);
 
-		prepareHelpLink (&element);
-	}
+	// Can't resolve links based on the already parsed dom-tree, because they can be inside string to be translated.
+	// I.e. resolving links before doing i18n will cause i18n-lookup to fail
+	QDomDocument doc;
+	if (doc.setContent (ret)) {
+		QDomNodeList link_nodes = doc.elementsByTagName ("link");
+		for (int i=link_nodes.count (); i >= 0; --i) {
+			QDomElement element = link_nodes.item (i).toElement ();
+			if (element.isNull ()) continue;
 
-	QString ret = xml->i18nElementText (fragment, true, DL_WARNING);
+			prepareHelpLink (&element);
+		}
+		ret = doc.toString ();
+	} else {
+		RK_DEBUG (APP, DL_ERROR, "Translated help fragment failed to parse: %s", qPrintable (ret));
+	}
 
 	RK_DEBUG (APP, DL_DEBUG, "%s", ret.toLatin1 ().data ());
 	return ret;





More information about the rkward-tracker mailing list