3
#include "GettextParser.hpp"
5
#include "GettextLexer.hpp"
11
int main(int argc, char **argv)
13
if ( argc != 2 && argc != 4 ) {
14
qWarning( "usage: %s [--text translation] potfile", argv[0] );
18
QString translation = "xx";
22
if( argv[1]!=QString("--text") ) {
23
qWarning( "usage: %s [--text translation] potfile", argv[0] );
26
translation = QString::fromLocal8Bit(argv[2]);
36
GettextLexer lexer(s);
37
GettextParser parser(lexer);
38
translated = parser.file();
40
} catch(exception& e) {
41
cerr << "exception: " << e.what() << endl;
45
const bool is_desktop = filename.find( "desktop_") >= 0;
47
// The header is the last item (due too the sorting)
48
MsgList::const_iterator header = --translated.end();
49
if ( ( header == translated.end() ) || ( ! ( *header ).msgid.isEmpty() ) )
51
cerr << "Cannot find correct header msgid\n";
52
cout << "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
53
cout << "\"Plural-Forms: nplurals=1; plural=0;\\n\"\n";
57
QStringList headerLines = QStringList::split( "\\n", ( *header ).msgstr, false );
58
QFileInfo fi( QString::fromLocal8Bit( filename ) );
59
QString projectId( "Project-Id-Version: " );
60
projectId += fi.baseName( false );
61
headerLines.gres( QRegExp( "^Project-Id-Version:.*" ), projectId );
62
headerLines.gres( QRegExp( "^Last-Translator:.*" ), "Last-Translator: transxx program <null@kde.org>" );
63
headerLines.gres( QRegExp( "^Language-Team:.*" ), "Language-Team: Test Language <kde-i18n-doc@kde.org>" );
64
QString revisionDate ( "PO-Revision-Date: " );
65
const QDateTime dt = QDateTime::currentDateTime( Qt::UTC );
66
revisionDate += dt.toString( "yyyy-MM-dd hh:mm+0000" );
67
headerLines.gres( QRegExp( "^PO-Revision-Date:.*" ), revisionDate );
68
headerLines << "Plural-Forms: nplurals=1; plural=0;";
69
outputMsg ( "msgid", "" );
70
outputMsg ( "msgstr", escapePO( headerLines.join("\\n") + "\\n" ) );
74
for (MsgList::ConstIterator it = translated.begin();
75
it != translated.end(); ++it)
77
QString msgid = ( *it ).msgid;
78
QString msgid_plural = ( *it ).msgid_plural;
79
if ( !msgid.isEmpty() ) {
80
outputMsg("msgid", escapePO( msgid) );
82
if ( ! msgid_plural.isEmpty() ) {
83
outputMsg("msgid_plural", escapePO( msgid_plural ) );
88
if ( msgid.find( "Definition of PluralForm" ) != -1 ) {
89
outputMsg("msgstr", "NoPlural");
95
msgstr = msgid.left( msgid.find( '=' ) + 1);
96
msgstr += translation + msgid.mid( msgid.find( '=' ) + 1) + translation;
97
outputMsg( "msgstr", escapePO(msgstr) );
102
if (msgid.startsWith("_n: ") || msgid.startsWith("_: ") ) { // KDE extentions
103
msgid = msgid.mid(msgid.find("\\n") + 2, msgid.length());
106
if (msgid.endsWith("%"))
107
msgstr = translation + msgid + " " + translation;
109
msgstr = translation + msgid + translation;
111
// Note: msgid has been modified, so we need to go back to the original version by the help of the iterator
112
// (Gettext is not aware of the KDE-specific handling, so it really wants a \n at start and at end in the msgstr if they were in the msgid )
113
if ( ( *it ).msgid.endsWith( "\\n" ) && ! ( *it ).msgid.endsWith( "\\\\n" ))
115
if ( ( *it ).msgid.startsWith( "\\n" ) )
116
msgstr.prepend( "\n" );
118
if ( msgid_plural.isEmpty() ) {
119
outputMsg("msgstr", escapePO( msgstr) );
123
outputMsg("msgstr[0]", escapePO( msgstr) );