[rkward-cvs] SF.net SVN: rkward-code:[4971] trunk/rkward/rkward
tfry at users.sf.net
tfry at users.sf.net
Tue Oct 28 12:03:33 UTC 2014
Revision: 4971
http://sourceforge.net/p/rkward/code/4971
Author: tfry
Date: 2014-10-28 12:03:33 +0000 (Tue, 28 Oct 2014)
Log Message:
-----------
Make help pages translatable
Modified Paths:
--------------
trunk/rkward/rkward/misc/xmlhelper.cpp
trunk/rkward/rkward/misc/xmlhelper.h
trunk/rkward/rkward/plugin/rktext.cpp
trunk/rkward/rkward/windows/rkhtmlwindow.cpp
trunk/rkward/rkward/windows/rkhtmlwindow.h
Modified: trunk/rkward/rkward/misc/xmlhelper.cpp
===================================================================
--- trunk/rkward/rkward/misc/xmlhelper.cpp 2014-10-28 11:16:17 UTC (rev 4970)
+++ trunk/rkward/rkward/misc/xmlhelper.cpp 2014-10-28 12:03:33 UTC (rev 4971)
@@ -315,7 +315,7 @@
return def;
}
-QString XMLHelper::i18nElementText (const QDomElement &element, int debug_level) {
+QString XMLHelper::i18nElementText (const QDomElement &element, bool with_paragraphs, int debug_level) const {
RK_TRACE (XML);
QString ret;
@@ -328,6 +328,7 @@
}
} else {
displayError (&element, i18n ("Trying to retrieve contents of invalid element"), debug_level);
+ return QString ();
}
const QString context_attr ("i18n_context");
@@ -336,20 +337,23 @@
context = element.attribute (context_attr);
}
+ // 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 ()) {
if (!ret.isEmpty ()) ret.append ("\n");
- ret += "<p>" + context.isNull () ? catalog->translate (para) : catalog->translate (context, para) + "</p>";
+ QString text = context.isNull () ? catalog->translate (para) : catalog->translate (context, para);
+ if (with_paragraphs) ret += "<p>" + text + "</p>";
+ else ret += text;
}
}
return ret;
}
-void XMLHelper::displayError (const QDomNode *in_node, const QString &message, int debug_level, int message_level) {
+void XMLHelper::displayError (const QDomNode *in_node, const QString &message, int debug_level, int message_level) const {
RK_TRACE (XML);
if (message_level < debug_level) message_level = debug_level;
Modified: trunk/rkward/rkward/misc/xmlhelper.h
===================================================================
--- trunk/rkward/rkward/misc/xmlhelper.h 2014-10-28 11:16:17 UTC (rev 4970)
+++ trunk/rkward/rkward/misc/xmlhelper.h 2014-10-28 12:03:33 UTC (rev 4971)
@@ -131,18 +131,19 @@
bool getBoolAttribute (const QDomElement &element, const QString &name, bool def, int debug_level);
/** Gets a string representation of whatever is *inside* the element. Contrary to QDomElement::text(), this includes child tags.
- * Text is normalized, i18n'ed, put inside '<p></p>'-tags (unless empty), and double newlines are split into separate paragraphs.
+ * Text is normalized and i18n'ed.
* @param element the element of interest
+ * @param with_paragraphs If true, put text inside '<p></p>'-tags (unless empty), and double newlines are split into separate paragraphs
* @param debug_level level of debug message to generate in case of failure (i.e. the element is null)
* @returns the contents as a QString (may be empty) */
- QString i18nElementText (const QDomElement &element, int debug_level);
+ QString i18nElementText (const QDomElement &element, bool with_paragraphs, int debug_level) const;
/** displays a custom-error message (also used internally by XMLHelper to display errors
@param in_node a pointer to the node/element to which the error relates (or 0). If given and non-zero, a "backtrace" of where the error is located will be generated
@param message the error-message to display
@param debug_level the debug level to show the message at (highestError () will be adujsted if applicable)
@param message_level sometime you may want to make sure your message is being shown even if it is not very important to your code. For instance, if there is a typo/illegal value in an optional setting, your code can continue using a reasonable default, but the user should still be notified of this error. If you omit this parameter or set it to something smaller that debug_level, debug_level will be used instead. */
- void displayError (const QDomNode *in_node, const QString &message, int debug_level, int message_level=-1);
+ void displayError (const QDomNode *in_node, const QString &message, int debug_level, int message_level=-1) const;
private:
/** copy the node list into a child list. The main effect is that a child list is not updated according to document changes */
XMLChildList nodeListToChildList (const QDomNodeList &from);
Modified: trunk/rkward/rkward/plugin/rktext.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rktext.cpp 2014-10-28 11:16:17 UTC (rev 4970)
+++ trunk/rkward/rkward/plugin/rktext.cpp 2014-10-28 12:03:33 UTC (rev 4971)
@@ -56,7 +56,7 @@
label->setFont (font);
}
- QString initial_text = xml->i18nElementText (element, DL_ERROR);
+ QString initial_text = xml->i18nElementText (element, true, DL_ERROR);
// create and add property
addChild ("text", text = new RKComponentPropertyBase (this, true));
Modified: trunk/rkward/rkward/windows/rkhtmlwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.cpp 2014-10-28 11:16:17 UTC (rev 4970)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.cpp 2014-10-28 12:03:33 UTC (rev 4971)
@@ -2,7 +2,7 @@
rkhtmlwindow - description
-------------------
begin : Wed Oct 12 2005
- copyright : (C) 2005-2013 by Thomas Friedrichsmeier
+ copyright : (C) 2005-2014 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -52,6 +52,7 @@
#include "../misc/xmlhelper.h"
#include "../misc/rkxmlguisyncer.h"
#include "../misc/rkprogresscontrol.h"
+#include "../misc/rkmessagecatalog.h"
#include "../plugin/rkcomponentmap.h"
#include "../windows/rkworkplace.h"
#include "../windows/rkworkplaceview.h"
@@ -499,7 +500,7 @@
chandle = componentPathToHandle (url.path ());
if (!chandle) return false;
}
- XMLHelper component_xml (for_component ? chandle->getFilename () : QString ());
+ XMLHelper component_xml (for_component ? chandle->getFilename () : QString (), for_component ? chandle->messageCatalog () : 0);
QString help_file_name;
QDomElement element;
QDomElement component_doc_element;
@@ -521,7 +522,9 @@
RK_DEBUG (APP, DL_DEBUG, "rendering help page for local file %s", help_file_name.toLatin1().data());
// open help file
- XMLHelper help_xml (help_file_name);
+ const RKMessageCatalog *catalog = component_xml.messageCatalog ();
+ if (!for_component) catalog = RKMessageCatalog::getCatalog ("rkward__pages", RKCommonFunctions::getRKWardDataDir () + "po/");
+ XMLHelper help_xml (help_file_name, catalog);
QDomElement help_doc_element = help_xml.openXMLFile (DL_ERROR);
if (help_doc_element.isNull () && (!for_component)) return false;
@@ -532,9 +535,7 @@
page_title = chandle->getLabel ();
} else {
element = help_xml.getChildElement (help_doc_element, "title", DL_WARNING);
- if (!element.isNull ()) {
- page_title = element.text ();
- }
+ page_title = help_xml.i18nElementText (element, false, DL_WARNING);
}
writeHTML ("<html><head><title>" + page_title + "</title><link rel=\"stylesheet\" type=\"text/css\" href=\"" + css_filename + "\"></head>\n<body><div id=\"main\">\n<h1>" + page_title + "</h1>\n");
@@ -563,22 +564,22 @@
element = help_xml.getChildElement (help_doc_element, "summary", DL_INFO);
if (!element.isNull ()) {
writeHTML (startSection ("summary", i18n ("Summary"), QString (), &anchors, &anchornames));
- writeHTML (renderHelpFragment (element));
+ writeHTML (renderHelpFragment (element, &help_xml));
}
element = help_xml.getChildElement (help_doc_element, "usage", DL_INFO);
if (!element.isNull ()) {
writeHTML (startSection ("usage", i18n ("Usage"), QString (), &anchors, &anchornames));
- writeHTML (renderHelpFragment (element));
+ writeHTML (renderHelpFragment (element, &help_xml));
}
XMLChildList section_elements = help_xml.getChildElements (help_doc_element, "section", DL_INFO);
for (XMLChildList::iterator it = section_elements.begin (); it != section_elements.end (); ++it) {
- QString title = help_xml.getStringAttribute (*it, "title", QString (), DL_WARNING);
- QString shorttitle = help_xml.getStringAttribute (*it, "shorttitle", QString (), DL_DEBUG);
+ QString title = help_xml.i18nStringAttribute (*it, "title", QString (), DL_WARNING);
+ QString shorttitle = help_xml.i18nStringAttribute (*it, "shorttitle", QString (), DL_DEBUG);
QString id = help_xml.getStringAttribute (*it, "id", QString (), DL_WARNING);
writeHTML (startSection (id, title, shorttitle, &anchors, &anchornames));
- writeHTML (renderHelpFragment (*it));
+ writeHTML (renderHelpFragment (*it, &help_xml));
}
// the section "settings" is the most complicated, as the labels of the individual GUI items has to be fetched from the component description. Of course it is only meaningful for component help, and not rendered for top level help pages.
@@ -590,17 +591,17 @@
for (XMLChildList::iterator it = setting_elements.begin (); it != setting_elements.end (); ++it) {
if ((*it).tagName () == "setting") {
QString id = help_xml.getStringAttribute (*it, "id", QString (), DL_WARNING);
- QString title = help_xml.getStringAttribute (*it, "title", QString (), DL_INFO);
+ QString title = help_xml.i18nStringAttribute (*it, "title", QString (), DL_INFO);
if (title.isEmpty ()) {
QDomElement source_element = component_xml.findElementWithAttribute (component_doc_element, "id", id, true, DL_WARNING);
if (source_element.isNull ()) RK_DEBUG (PLUGIN, DL_ERROR, "No such UI element: %s", qPrintable (id));
title = component_xml.i18nStringAttribute (source_element, "label", i18n ("Unnamed GUI element"), DL_WARNING);
}
writeHTML ("<h4>" + title + "</h4>");
- writeHTML (renderHelpFragment (*it));
+ writeHTML (renderHelpFragment (*it, &help_xml));
} else if ((*it).tagName () == "caption") {
QString id = help_xml.getStringAttribute (*it, "id", QString (), DL_WARNING);
- QString title = help_xml.getStringAttribute (*it, "title", QString (), DL_INFO);
+ QString title = help_xml.i18nStringAttribute (*it, "title", QString (), DL_INFO);
QDomElement source_element = component_xml.findElementWithAttribute (component_doc_element, "id", id, true, DL_WARNING);
if (source_element.isNull ()) RK_DEBUG (PLUGIN, DL_ERROR, "No such UI element: %s", qPrintable (id));
title = component_xml.i18nStringAttribute (source_element, "label", title, DL_WARNING);
@@ -616,14 +617,14 @@
element = help_xml.getChildElement (help_doc_element, "related", DL_INFO);
if (!element.isNull ()) {
writeHTML (startSection ("related", i18n ("Related functions and pages"), QString (), &anchors, &anchornames));
- writeHTML (renderHelpFragment (element));
+ writeHTML (renderHelpFragment (element, &help_xml));
}
// "technical" section
element = help_xml.getChildElement (help_doc_element, "technical", DL_INFO);
if (!element.isNull ()) {
writeHTML (startSection ("technical", i18n ("Technical details"), QString (), &anchors, &anchornames));
- writeHTML (renderHelpFragment (element));
+ writeHTML (renderHelpFragment (element, &help_xml));
}
if (for_component) {
@@ -639,7 +640,7 @@
if (for_component) {
element = component_xml.getChildElement (component_doc_element, "about", DL_INFO);
if (element.isNull ()) {
- XMLHelper pluginmap_helper (chandle->getPluginmapFilename ());
+ XMLHelper pluginmap_helper (chandle->getPluginmapFilename (), chandle->messageCatalog ());
element = pluginmap_helper.openXMLFile (DL_ERROR);
element = pluginmap_helper.getChildElement (element, "about", DL_INFO);
}
@@ -676,7 +677,7 @@
return (true);
}
-QString RKHTMLWindow::renderHelpFragment (QDomElement &fragment) {
+QString RKHTMLWindow::renderHelpFragment (QDomElement &fragment, const XMLHelper *xml) {
RK_TRACE (APP);
// prepare all internal links
@@ -688,17 +689,8 @@
prepareHelpLink (&element);
}
- // render to string
- QString ret;
- QTextStream stream (&ret, QIODevice::WriteOnly);
- for (QDomNode node = fragment.firstChild (); !node.isNull (); node = node.nextSibling ()) {
- node.save (stream, 0);
- }
+ QString ret = xml->i18nElementText (fragment, true, DL_WARNING);
- ret.prepend ("<p>");
- ret.append ("</p>");
- ret.replace ("\n\n", "</p>\n<p>");
-
RK_DEBUG (APP, DL_DEBUG, "%s", ret.toLatin1 ().data ());
return ret;
}
@@ -719,10 +711,10 @@
} else if (url.host () == "page") {
QString help_base_dir = RKCommonFunctions::getRKWardDataDir () + "pages/";
- XMLHelper xml (help_base_dir + url.path () + ".rkh");
+ XMLHelper xml (help_base_dir + url.path () + ".rkh", RKMessageCatalog::getCatalog ("rkward__pages", RKCommonFunctions::getRKWardDataDir () + "po/"));
QDomElement doc_element = xml.openXMLFile (DL_WARNING);
QDomElement title_element = xml.getChildElement (doc_element, "title", DL_WARNING);
- text = title_element.text ();
+ text = xml.i18nElementText (title_element, false, DL_WARNING);
}
if (text.isEmpty ()) {
Modified: trunk/rkward/rkward/windows/rkhtmlwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.h 2014-10-28 11:16:17 UTC (rev 4970)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.h 2014-10-28 12:03:33 UTC (rev 4971)
@@ -2,7 +2,7 @@
rkhtmlwindow - description
-------------------
begin : Wed Oct 12 2005
- copyright : (C) 2005, 2006, 2007, 2009, 2011 by Thomas Friedrichsmeier
+ copyright : (C) 2005, 2006, 2007, 2009, 2011, 2014 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -32,6 +32,7 @@
class QAction;
class QDomElement;
class RKComponentHandle;
+class XMLHelper;
/**
\brief Show html files.
@@ -132,7 +133,7 @@
// for dealing with rkward://[page|component]-pages
bool renderRKHelp (const KUrl &url);
- QString renderHelpFragment (QDomElement &fragment);
+ QString renderHelpFragment (QDomElement &fragment, const XMLHelper *xml);
void prepareHelpLink (QDomElement *link_element);
QString componentPathToId (QString path);
RKComponentHandle *componentPathToHandle (QString path);
More information about the rkward-tracker
mailing list