Changeset 2817 for vidalia/trunk/src
- Timestamp:
- 07/02/08 01:16:49 (5 months ago)
- Location:
- vidalia/trunk/src/tools/ts2po
- Files:
-
- 2 modified
-
CMakeLists.txt (modified) (1 diff)
-
ts2po.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vidalia/trunk/src/tools/ts2po/CMakeLists.txt
r2747 r2817 12 12 13 13 ## Define this version of ts2po 14 set(VERSION "0. 1")14 set(VERSION "0.2") 15 15 16 16 ## Include the source and binary directories so it can find out configured -
vidalia/trunk/src/tools/ts2po/ts2po.cpp
r2814 r2817 10 10 11 11 #include <QFile> 12 #include <QFileInfo> 12 13 #include <QDomDocument> 13 14 #include <QTextStream> … … 23 24 #define TS_ELEMENT_SOURCE "source" 24 25 #define TS_ELEMENT_TRANSLATION "translation" 26 #define TS_ELEMENT_LOCATION "location" 27 #define TS_ATTR_FILENAME "filename" 28 #define TS_ATTR_LINE "line" 25 29 26 30 … … 41 45 QString tstamp = create_po_timestamp(); 42 46 43 header.append("#,fuzzy\n");44 47 header.append("msgid \"\"\n"); 45 48 header.append("msgstr \"\"\n"); … … 61 64 } 62 65 66 /** Parse the filename from the relative or absolute path given in 67 * <b>filePath</b>. */ 68 QString 69 parse_filename(const QString &filePath) 70 { 71 QFileInfo file(filePath); 72 return file.fileName(); 73 } 74 63 75 /** Convert the messages in <b>context</b> to PO format. The output will be 64 76 * appended to <b>po</b>. Returns the number of source messages converted on … … 67 79 convert_context(const QDomElement &context, QString *po, QString *errorMessage) 68 80 { 69 QString msgid, msgstr; 81 QString msgctxt, msgid, msgstr; 82 QString filename, line; 70 83 QDomElement location, source, translation; 71 84 int n = 0; … … 80 93 return -1; 81 94 } 95 msgctxt = name.text(); 82 96 83 97 QDomElement msg = context.firstChildElement(TS_ELEMENT_MESSAGE); … … 102 116 msgstr.replace("\n", "\"\n\""); 103 117 118 /* Try to extract the <location> tags (optional) */ 119 location = msg.firstChildElement(TS_ELEMENT_LOCATION); 120 filename = parse_filename(location.attribute(TS_ATTR_FILENAME)); 121 line = location.attribute(TS_ATTR_LINE); 122 104 123 /* Format the .po entry for this string */ 105 (*po).append(QString("#: %1#%2\n").arg(name.text()).arg(++n)); 124 if (!filename.isEmpty() && !line.isEmpty()) 125 (*po).append(QString("#: %1:%2\n").arg(filename).arg(line)); 126 (*po).append(QString("msgctxt \"%1\"\n").arg(msgctxt)); 106 127 (*po).append(QString("msgid \"%1\"\n").arg(msgid)); 107 128 (*po).append(QString("msgstr \"%1\"\n").arg(msgstr)); … … 110 131 /* Find the next source message in the current context */ 111 132 msg = msg.nextSiblingElement(TS_ELEMENT_MESSAGE); 133 n++; 112 134 } 113 135 return n;
