100int main(
int argc,
char *argv[])
102 QCoreApplication app(argc, argv);
103#ifndef QT_BOOTSTRAPPED
105 QTranslator translator;
106 QTranslator qtTranslator;
107 QString resourceDir = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
108 if (translator.load(
"linguist_en"_L1, resourceDir)
109 && qtTranslator.load(
"qt_en"_L1, resourceDir)) {
110 app.installTranslator(&translator);
111 app.installTranslator(&qtTranslator);
116 QStringList args = app.arguments();
118 QString inFormat(
"auto"_L1);
120 QString outFormat(
"auto"_L1);
121 QString targetLanguage;
122 QString sourceLanguage;
123 bool dropTranslations =
false;
124 bool noObsolete =
false;
125 bool noFinished =
false;
126 bool noUntranslated =
false;
127 bool verbose =
false;
128 bool noUiLines =
false;
129 bool pluralOnly =
false;
135 for (
int i = 1; i < args.size(); ++i) {
136 const QString &arg = args.at(i);
137 if (arg.startsWith(
"--"_L1))
138 args[i].remove(0, 1);
139 if (arg ==
"-o"_L1 || arg ==
"-output-file"_L1) {
140 if (++i >= args.size())
142 outFileName = args[i];
143 }
else if (arg ==
"-of"_L1 || arg ==
"-output-format"_L1) {
144 if (++i >= args.size())
147 }
else if (arg ==
"-i"_L1 || arg ==
"-input-file"_L1) {
148 if (++i >= args.size())
152 file.format = inFormat;
153 inFiles.append(file);
154 }
else if (arg ==
"-if"_L1 || arg ==
"-input-format"_L1) {
155 if (++i >= args.size())
158 }
else if (arg ==
"-drop-tag"_L1 || arg ==
"-drop-tags"_L1) {
159 if (++i >= args.size())
161 cd.m_dropTags.append(args[i]);
162 }
else if (arg ==
"-drop-translations"_L1) {
163 dropTranslations =
true;
164 }
else if (arg ==
"-target-language"_L1) {
165 if (++i >= args.size())
167 targetLanguage = args[i];
168 }
else if (arg ==
"-source-language"_L1) {
169 if (++i >= args.size())
171 sourceLanguage = args[i];
172 }
else if (arg.startsWith(
"-h"_L1)) {
175 }
else if (arg ==
"-no-obsolete"_L1) {
177 }
else if (arg ==
"-no-finished"_L1) {
179 }
else if (arg ==
"-no-untranslated"_L1) {
180 noUntranslated =
true;
181 }
else if (arg ==
"-sort-contexts"_L1) {
183 }
else if (arg ==
"-sort-messages"_L1) {
185 }
else if (arg ==
"-locations"_L1) {
186 if (++i >= args.size())
188 if (args[i] ==
"none"_L1)
190 else if (args[i] ==
"relative"_L1)
192 else if (args[i] ==
"absolute"_L1)
196 }
else if (arg ==
"-no-ui-lines"_L1) {
198 }
else if (arg ==
"-pluralonly"_L1) {
200 }
else if (arg ==
"-verbose"_L1) {
202 }
else if (arg.startsWith(u'-')) {
207 file.format = inFormat;
208 inFiles.append(file);
212 if (inFiles.isEmpty())
215 tr.setLanguageCode(Translator::guessLanguageCodeFromFileName(inFiles[0].name));
217 if (!tr.load(inFiles[0].name, cd, inFiles[0].format)) {
218 std::cerr << qPrintable(cd.error());
223 for (
int i = 1; i < inFiles.size(); ++i) {
225 if (!tr2.load(inFiles[i].name, cd, inFiles[i].format)) {
226 std::cerr << qPrintable(cd.error());
233 tr.appendDependencies(tr2.dependencies());
236 for (
const auto &file: inFiles) {
237 tr.satisfyDependency(file.name, file.format);
240 if (!targetLanguage.isEmpty())
241 tr.setLanguageCode(targetLanguage);
242 if (!sourceLanguage.isEmpty())
243 tr.setSourceLanguageCode(sourceLanguage);
250 if (dropTranslations)
260 if (!cd.errors().isEmpty()) {
261 std::cerr << qPrintable(cd.error());
264 if (!tr.save(outFileName, cd, outFormat)) {
265 std::cerr << qPrintable(cd.error());