[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r2817: Modify ts2po to use a 'msgctxt' line for specifying a messag (vidalia/trunk/src/tools/ts2po)



Author: edmanm
Date: 2008-07-02 01:16:49 -0400 (Wed, 02 Jul 2008)
New Revision: 2817

Modified:
   vidalia/trunk/src/tools/ts2po/CMakeLists.txt
   vidalia/trunk/src/tools/ts2po/ts2po.cpp
Log:
Modify ts2po to use a 'msgctxt' line for specifying a message's context,
rather than overloading the "#:" line (pootle > 1.0 supports msgctxt). Also
now use the "#:", as intended, for the string's filename and line number.


Modified: vidalia/trunk/src/tools/ts2po/CMakeLists.txt
===================================================================
--- vidalia/trunk/src/tools/ts2po/CMakeLists.txt	2008-07-02 02:09:22 UTC (rev 2816)
+++ vidalia/trunk/src/tools/ts2po/CMakeLists.txt	2008-07-02 05:16:49 UTC (rev 2817)
@@ -11,7 +11,7 @@
 ##
 
 ## Define this version of ts2po
-set(VERSION "0.1")
+set(VERSION "0.2")
 
 ## Include the source and binary directories so it can find out configured
 ## header file

Modified: vidalia/trunk/src/tools/ts2po/ts2po.cpp
===================================================================
--- vidalia/trunk/src/tools/ts2po/ts2po.cpp	2008-07-02 02:09:22 UTC (rev 2816)
+++ vidalia/trunk/src/tools/ts2po/ts2po.cpp	2008-07-02 05:16:49 UTC (rev 2817)
@@ -9,6 +9,7 @@
 */
 
 #include <QFile>
+#include <QFileInfo>
 #include <QDomDocument>
 #include <QTextStream>
 #include <QTextCodec>
@@ -22,6 +23,9 @@
 #define TS_ELEMENT_MESSAGE            "message"
 #define TS_ELEMENT_SOURCE             "source"
 #define TS_ELEMENT_TRANSLATION        "translation"
+#define TS_ELEMENT_LOCATION           "location"
+#define TS_ATTR_FILENAME              "filename"
+#define TS_ATTR_LINE                  "line"
 
 
 /** Return the current time (in UTC) in the format YYYY-MM-DD HH:MM+0000. */
@@ -40,7 +44,6 @@
   QString header;
   QString tstamp = create_po_timestamp();
 
-  header.append("#,fuzzy\n");
   header.append("msgid \"\"\n");
   header.append("msgstr \"\"\n");
   header.append("\"Project-Id-Version: "TS2PO_PROJECT_ID"\\n\"\n");
@@ -60,13 +63,23 @@
   return header;
 }
 
+/** Parse the filename from the relative or absolute path given in
+ * <b>filePath</b>. */
+QString
+parse_filename(const QString &filePath)
+{
+  QFileInfo file(filePath);
+  return file.fileName();
+}
+
 /** Convert the messages in <b>context</b> to PO format. The output will be
  * appended to <b>po</b>. Returns the number of source messages converted on
  * success, or -1 on error and <b>errorMessage</b> will be set. */
 int
 convert_context(const QDomElement &context, QString *po, QString *errorMessage)
 {
-  QString msgid, msgstr;
+  QString msgctxt, msgid, msgstr;
+  QString filename, line;
   QDomElement location, source, translation;
   int n = 0;
 
@@ -79,6 +92,7 @@
                                                  .arg(context.lineNumber());
     return -1;
   }
+  msgctxt = name.text();
 
   QDomElement msg = context.firstChildElement(TS_ELEMENT_MESSAGE);
   while (!msg.isNull()) {
@@ -101,14 +115,22 @@
     msgstr.replace("\"", "\\\"");
     msgstr.replace("\n", "\"\n\"");
   
+    /* Try to extract the <location> tags (optional) */
+    location = msg.firstChildElement(TS_ELEMENT_LOCATION);
+    filename = parse_filename(location.attribute(TS_ATTR_FILENAME));
+    line = location.attribute(TS_ATTR_LINE);
+
     /* Format the .po entry for this string */
-    (*po).append(QString("#: %1#%2\n").arg(name.text()).arg(++n));
+    if (!filename.isEmpty() && !line.isEmpty())
+      (*po).append(QString("#: %1:%2\n").arg(filename).arg(line));
+    (*po).append(QString("msgctxt \"%1\"\n").arg(msgctxt));
     (*po).append(QString("msgid \"%1\"\n").arg(msgid));
     (*po).append(QString("msgstr \"%1\"\n").arg(msgstr));
     (*po).append("\n");
   
     /* Find the next source message in the current context */
     msg = msg.nextSiblingElement(TS_ELEMENT_MESSAGE);
+    n++;
   }
   return n;
 }