1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// #define POXML_DEBUG
#include "parser.h"
#include "gettextpoutils.h"
#include <stdlib.h>
#include <iostream>
#include <qfileinfo.h>
#include <qdatetime.h>
#include <QList>
using namespace std;
int main( int argc, char **argv )
{
if (argc != 2) {
qWarning("usage: %s english-XML", argv[0]);
exit(1);
}
MsgList english = parseXML(argv[1]);
QMap<QString, int> msgids;
int index = 0;
for (MsgList::Iterator it = english.begin();
it != english.end(); )
{
if (msgids.contains((*it).msgid)) {
english[msgids[(*it).msgid]].lines += (*it).lines;
it = english.erase(it);
} else {
msgids.insert((*it).msgid, index);
index++;
it++;
}
}
const QDateTime now = QDateTime::currentDateTime().toUTC();
const QByteArray datestring = now.toString(QStringLiteral("yyyy-MM-dd hh:mm")).toUtf8() + "+0000";
po_file_t po = NULL;
po_message_iterator_t out_it = NULL;
const struct poheader headers[] = {
{ "Project-Id-Version", "PACKAGE VERSION" },
{ "Report-Msgid-Bugs-To", "https://bugs.kde.org" },
{ "POT-Creation-Date", datestring.constData() },
{ "PO-Revision-Date", "YEAR-MO-DA HO:MI+ZONE" },
{ "Last-Translator", "FULL NAME <EMAIL@ADDRESS>" },
{ "Language-Team", "LANGUAGE <kde-i18n-doc@kde.org>" },
{ "MIME-Version", "1.0" },
{ "Content-Type", "text/plain; charset=UTF-8" },
{ "Content-Transfer-Encoding", "8bit" },
{ nullptr, nullptr }
};
const char headercomment[] = "SOME DESCRIPTIVE TITLE.\n"
"FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n"
"\n";
#ifdef POXML_DEBUG
qDebug("creating PO header");
#endif
if (!createPOWithHeader(headers, headercomment, &po, &out_it)) {
return 1;
}
const QByteArray fname = QFileInfo(QFile::decodeName(argv[1])).fileName().toUtf8();
for (const MsgBlock &block : std::as_const(english))
{
#ifdef POXML_DEBUG
qDebug("adding message: %s", qPrintable(block.msgid));
#endif
po_message_t msg = po_message_create();
if (!msg) {
po_message_iterator_free(out_it);
po_file_free(po);
return 1;
}
const QByteArray tagstring = "Tag: " + block.tag.toUtf8();
po_message_set_extracted_comments(msg, tagstring.constData());
for (const BlockInfo &bi : block.lines) {
po_message_add_filepos(msg, fname.constData(), bi.start_line);
}
po_message_set_format(msg, "c-format", 0);
po_message_set_msgid(msg, StructureParser::descapeLiterals(block.msgid).toUtf8().constData());
po_message_set_msgstr(msg, block.msgstr.toUtf8().constData());
po_message_insert(out_it, msg);
}
po_message_iterator_free(out_it);
#ifdef POXML_DEBUG
qDebug("outputting PO file");
#endif
po_file_write(po, "/dev/stdout", &po_msg_handler_cerr);
po_file_free(po);
return 0;
}
|