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

tfry at users.sf.net tfry at users.sf.net
Tue Oct 28 10:04:08 UTC 2014


Revision: 4969
          http://sourceforge.net/p/rkward/code/4969
Author:   tfry
Date:     2014-10-28 10:04:07 +0000 (Tue, 28 Oct 2014)
Log Message:
-----------
Make <text> elements translatable.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/misc/xmlhelper.cpp
    trunk/rkward/rkward/misc/xmlhelper.h
    trunk/rkward/rkward/plugin/rktext.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2014-10-28 09:51:39 UTC (rev 4968)
+++ trunk/rkward/ChangeLog	2014-10-28 10:04:07 UTC (rev 4969)
@@ -6,12 +6,15 @@
     - Message extraction: Should we do this in R, using XiMpLe? That might allow us to give better context / comments
     - Don't forget to write documentation
     - What should be the policy regarding installing translations (80% criterion)
-    - Where should the extraction script look for i18n comments (before element, within element)?
     - discuss i18n_context vs. comments
-    - Important pitfalls: String comparison with checkbox / radio labels! (Definitely wrong in some plugins)
+    - Important pitfalls: String comparison with checkbox / radio labels! (Probably wrong in some plugins)
+    - i18n'ed plugins vs. automated tests
+      - Sure, we can run automated tests under C locale. But it would be nice to have an additional check that translations don't cause
+        any obvious problems.
+        - At least we could check for errors
+        - Perhaps a special diff of the generated R commands, where all quoted strings and comments are stripped?
    - i18n calls
     - wcgrep getStringAttribute.*i18n
-    - is <caption title="XYZ"> used, anywhere?
     - element text
 
 --- Version 0.6.2 - Oct-20-2014

Modified: trunk/rkward/rkward/misc/xmlhelper.cpp
===================================================================
--- trunk/rkward/rkward/misc/xmlhelper.cpp	2014-10-28 09:51:39 UTC (rev 4968)
+++ trunk/rkward/rkward/misc/xmlhelper.cpp	2014-10-28 10:04:07 UTC (rev 4969)
@@ -228,7 +228,6 @@
 	return ret;
 }
 
-
 QString XMLHelper::getStringAttribute (const QDomElement &element, const QString &name, const QString &def, int debug_level) {
 	RK_TRACE (XML);
 
@@ -316,7 +315,7 @@
 	return def;
 }
 
-QString XMLHelper::getRawContents (const QDomElement &element, int debug_level) {
+QString XMLHelper::i18nElementText (const QDomElement &element, int debug_level) {
 	RK_TRACE (XML);
 
 	QString ret;
@@ -331,6 +330,16 @@
 		displayError (&element, i18n ("Trying to retrieve contents of invalid element"), debug_level);
 	}
 
+	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>" + catalog->translate (para) + "</p>";
+		}
+	}
+
 	return ret;
 }
 

Modified: trunk/rkward/rkward/misc/xmlhelper.h
===================================================================
--- trunk/rkward/rkward/misc/xmlhelper.h	2014-10-28 09:51:39 UTC (rev 4968)
+++ trunk/rkward/rkward/misc/xmlhelper.h	2014-10-28 10:04:07 UTC (rev 4969)
@@ -131,10 +131,11 @@
 	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.
  * @param element the element of interest
  * @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 getRawContents (const QDomElement &element, int debug_level);
+	QString i18nElementText (const QDomElement &element, int debug_level);
 
 /** 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

Modified: trunk/rkward/rkward/plugin/rktext.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rktext.cpp	2014-10-28 09:51:39 UTC (rev 4968)
+++ trunk/rkward/rkward/plugin/rktext.cpp	2014-10-28 10:04:07 UTC (rev 4969)
@@ -2,7 +2,7 @@
                           rktext.cpp  -  description
                              -------------------
     begin                : Sun Nov 10 2002
-    copyright            : (C) 2002, 2006, 2007, 2012 by Thomas Friedrichsmeier
+    copyright            : (C) 2002, 2006, 2007, 2012, 2014 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -41,10 +41,6 @@
 	label->setWordWrap (true);
 	vbox->addWidget (label);
 
-	QString initial_text = xml->getRawContents (element, DL_ERROR);
-	if (!initial_text.isEmpty ()) initial_text = "<p>" + initial_text + "</p>";
-	initial_text.replace ("\n\n", "</p>\n<p>");
-
 	int type = xml->getMultiChoiceAttribute (element, "type", "normal;warning;error", 0, DL_INFO);
 	if (type != 0) {
 		QFont font = label->font ();
@@ -60,8 +56,7 @@
 		label->setFont (font);
 	}
 
-	// strip final newline
-	initial_text.truncate (initial_text.length () -1);
+	QString initial_text = xml->i18nElementText (element, DL_ERROR);
 
 	// create and add property
 	addChild ("text", text = new RKComponentPropertyBase (this, true));





More information about the rkward-tracker mailing list