summaryrefslogtreecommitdiffstats
path: root/poxml/xml2pot.cpp
blob: 658e557b0b2017181c284e5bd5717a924c4cd889 (plain)
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
#include "parser.h"
#include <stdlib.h>
#include <iostream>
#include <tqfileinfo.h>
#include <tqdatetime.h>

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]);

    TQMap<TQString, 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;
            MsgList::Iterator tmp = it;
            it++;
            english.remove(tmp);
        } else {
            msgids.insert((*it).msgid, index);
            index++;
            it++;
        }
    }

    const TQDateTime now = TQDateTime::tqcurrentDateTime( Qt::UTC );
    
    cout << "# SOME DESCRIPTIVE TITLE.\n";
    cout << "# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n";
    cout << "#\n";
    cout << "#, fuzzy\n";
    cout << "msgid \"\"\n";
    cout << "msgstr \"\"\n";
    cout << "\"Project-Id-Version: PACKAGE VERSION\\n\"\n";
    cout << "\"Report-Msgid-Bugs-To: http://bugs.kde.org\\n\"\n";
    cout << "\"POT-Creation-Date: " << now.toString("yyyy-MM-dd hh:mm").utf8().data() << "+0000\\n\"\n";
    cout << "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n";
    cout << "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n";
    cout << "\"Language-Team: LANGUAGE <tde-i18n-doc@kde.org>\\n\"\n";
    cout << "\"MIME-Version: 1.0\\n\"\n";
    cout << "\"Content-Type: application/x-xml2pot; charset=UTF-8\\n\"\n";
    cout << "\"Content-Transfer-Encoding: 8bit\\n\"\n";
    cout << "\n";

    const TQString fname = TQFileInfo(argv[1]).fileName();

    for (MsgList::ConstIterator it = english.begin();
         it != english.end(); ++it)
    {
        cout << "#. Tag: " << (*it).tag.utf8().data() << endl;
        cout << "#: ";
        for (TQValueList<BlockInfo>::ConstIterator it2 =
                 (*it).lines.begin(); it2 != (*it).lines.end(); it2++) {
            if (it2 != (*it).lines.begin())
                cout << " ";
            cout << fname.utf8().data() << ":" << (*it2).start_line;

        }
        cout << "\n";
        cout << "#, no-c-format\n";
        outputMsg("msgid", StructureParser::descapeLiterals( (*it).msgid ));
        outputMsg("msgstr", (*it).msgstr );
        cout << "\n";
    }

    return 0;
}