96int main(
int argc,
char *argv[])
98 QCoreApplication app(argc, argv);
99#ifndef QT_BOOTSTRAPPED
101 QTranslator translator;
102 QTranslator qtTranslator;
103 QString sysLocale = QLocale::system().name();
104 QString resourceDir = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
105 if (translator.load(QLatin1String(
"linguist_") + sysLocale, resourceDir)
106 && qtTranslator.load(QLatin1String(
"qt_") + sysLocale, resourceDir)) {
107 app.installTranslator(&translator);
108 app.installTranslator(&qtTranslator);
113 QStringList args = app.arguments();
115 QString inFormat(QLatin1String(
"auto"));
117 QString outFormat(QLatin1String(
"auto"));
118 QString targetLanguage;
119 QString sourceLanguage;
120 bool dropTranslations =
false;
121 bool noObsolete =
false;
122 bool noFinished =
false;
123 bool noUntranslated =
false;
124 bool verbose =
false;
125 bool noUiLines =
false;
126 bool pluralOnly =
false;
132 for (
int i = 1; i < args.size(); ++i) {
133 if (args[i].startsWith(QLatin1String(
"--")))
134 args[i].remove(0, 1);
135 if (args[i] == QLatin1String(
"-o")
136 || args[i] == QLatin1String(
"-output-file")) {
137 if (++i >= args.size())
139 outFileName = args[i];
140 }
else if (args[i] == QLatin1String(
"-of")
141 || args[i] == QLatin1String(
"-output-format")) {
142 if (++i >= args.size())
145 }
else if (args[i] == QLatin1String(
"-i")
146 || args[i] == QLatin1String(
"-input-file")) {
147 if (++i >= args.size())
151 file.format = inFormat;
152 inFiles.append(file);
153 }
else if (args[i] == QLatin1String(
"-if")
154 || args[i] == QLatin1String(
"-input-format")) {
155 if (++i >= args.size())
158 }
else if (args[i] == QLatin1String(
"-drop-tag") || args[i] == QLatin1String(
"-drop-tags")) {
159 if (++i >= args.size())
161 cd.m_dropTags.append(args[i]);
162 }
else if (args[i] == QLatin1String(
"-drop-translations")) {
163 dropTranslations =
true;
164 }
else if (args[i] == QLatin1String(
"-target-language")) {
165 if (++i >= args.size())
167 targetLanguage = args[i];
168 }
else if (args[i] == QLatin1String(
"-source-language")) {
169 if (++i >= args.size())
171 sourceLanguage = args[i];
172 }
else if (args[i].startsWith(QLatin1String(
"-h"))) {
175 }
else if (args[i] == QLatin1String(
"-no-obsolete")) {
177 }
else if (args[i] == QLatin1String(
"-no-finished")) {
179 }
else if (args[i] == QLatin1String(
"-no-untranslated")) {
180 noUntranslated =
true;
181 }
else if (args[i] == QLatin1String(
"-sort-contexts")) {
183 }
else if (args[i] == QLatin1String(
"-locations")) {
184 if (++i >= args.size())
186 if (args[i] == QLatin1String(
"none"))
188 else if (args[i] == QLatin1String(
"relative"))
190 else if (args[i] == QLatin1String(
"absolute"))
194 }
else if (args[i] == QLatin1String(
"-no-ui-lines")) {
196 }
else if (args[i] == QLatin1String(
"-pluralonly")) {
198 }
else if (args[i] == QLatin1String(
"-verbose")) {
200 }
else if (args[i].startsWith(QLatin1Char(
'-'))) {
205 file.format = inFormat;
206 inFiles.append(file);
210 if (inFiles.isEmpty())
213 tr.setLanguageCode(Translator::guessLanguageCodeFromFileName(inFiles[0].name));
215 if (!tr.load(inFiles[0].name, cd, inFiles[0].format)) {
216 std::cerr << qPrintable(cd.error());
221 for (
int i = 1; i < inFiles.size(); ++i) {
223 if (!tr2.load(inFiles[i].name, cd, inFiles[i].format)) {
224 std::cerr << qPrintable(cd.error());
232 if (!targetLanguage.isEmpty())
233 tr.setLanguageCode(targetLanguage);
234 if (!sourceLanguage.isEmpty())
235 tr.setSourceLanguageCode(sourceLanguage);
242 if (dropTranslations)
252 if (!cd.errors().isEmpty()) {
253 std::cerr << qPrintable(cd.error());
256 if (!tr.save(outFileName, cd, outFormat)) {
257 std::cerr << qPrintable(cd.error());