~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/linguist/qm2ts/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the linguist application of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include <metatranslator.h>
 
30
 
 
31
#include <qregexp.h>
 
32
#include <qstring.h>
 
33
#include <qtranslator.h>
 
34
#include <stdio.h>
 
35
 
 
36
typedef QList<TranslatorMessage> TML;
 
37
 
 
38
static void printUsage()
 
39
{
 
40
    fprintf( stderr, "Usage:\n"
 
41
             "    qm2ts [ options ] qm-files\n"
 
42
             "Options:\n"
 
43
             "    -help  Display this information and exit\n"
 
44
             "    -verbose\n"
 
45
             "           Explain what is being done\n"
 
46
             "    -version\n"
 
47
             "           Display the version of qm2ts and exit\n" );
 
48
}
 
49
 
 
50
int main( int argc, char **argv )
 
51
{
 
52
    bool verbose = false;
 
53
    int numQmFiles = 0;
 
54
 
 
55
    for ( int i = 1; i < argc; i++ ) {
 
56
        if ( qstrcmp(argv[i], "-help") == 0 ) {
 
57
            printUsage();
 
58
            return 0;
 
59
        } else if ( qstrcmp(argv[i], "-verbose") == 0 ) {
 
60
            verbose = true;
 
61
            continue;
 
62
        } else if ( qstrcmp(argv[i], "-version") == 0 ) {
 
63
            fprintf( stderr, "qm2ts version %s\n", QT_VERSION_STR );
 
64
            return 0;
 
65
        }
 
66
 
 
67
        numQmFiles++;
 
68
        Translator tor( 0 );
 
69
        if ( tor.load(argv[i], ".") ) {
 
70
            QString g = argv[i];
 
71
            g.replace( QRegExp(QString("\\.qm$")), QString() );
 
72
            g += QString( ".ts" );
 
73
 
 
74
            if ( verbose )
 
75
                fprintf( stderr, "Generating '%s'...\n", g.toLatin1().data() );
 
76
 
 
77
            MetaTranslator metator;
 
78
            int ignored = 0;
 
79
 
 
80
            TML all = tor.messages();
 
81
            TML::Iterator it;
 
82
            for ( it = all.begin(); it != all.end(); ++it ) {
 
83
                if ( (*it).sourceText() == 0 ) {
 
84
                    ignored++;
 
85
                } else {
 
86
                    QByteArray context = (*it).context();
 
87
                    if ( context.isEmpty() )
 
88
                        context = "@default";
 
89
                    metator.insert( MetaTranslatorMessage(context,
 
90
                                    (*it).sourceText(), (*it).comment(),
 
91
                                    (*it).translation(), false,
 
92
                                    MetaTranslatorMessage::Finished) );
 
93
                }
 
94
            }
 
95
 
 
96
            if ( !metator.save(g) ) {
 
97
                fprintf( stderr,
 
98
                         "qm2ts warning: For some reason, I cannot save '%s'\n",
 
99
                         g.toLatin1().constData() );
 
100
            } else {
 
101
                if ( verbose ) {
 
102
                    int converted = (int) metator.messages().count();
 
103
                    fprintf( stderr, " %d message%s converted (%d ignored)\n",
 
104
                             converted, converted == 1 ? "" : "s", ignored );
 
105
                }
 
106
                if ( ignored > 0 )
 
107
                    fprintf( stderr,
 
108
                             "qm2ts warning: File '%s' is not a Qt 2.x .qm"
 
109
                             " file (some information is lost)\n",
 
110
                             argv[i] );
 
111
            }
 
112
        } else {
 
113
            fprintf( stderr,
 
114
                     "qm2ts warning: For some reason, I cannot load '%s'\n",
 
115
                     argv[i] );
 
116
        }
 
117
    }
 
118
 
 
119
    if ( numQmFiles == 0 ) {
 
120
        printUsage();
 
121
        return 1;
 
122
    }
 
123
    return 0;
 
124
}