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