1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#include <profileutils.h>
5#include <runqttool.h>
6
7#include <QtCore/qcoreapplication.h>
8#include <QtCore/qdebug.h>
9#include <QtCore/qlibraryinfo.h>
10#include <QtCore/qtranslator.h>
11
12#include <iostream>
13
14QT_USE_NAMESPACE
15
16using namespace Qt::StringLiterals;
17
18static void printOut(const QString &out)
19{
20 std::cout << qPrintable(out);
21}
22
23static void printErr(const QString &out)
24{
25 std::cerr << qPrintable(out);
26}
27
28static void printUsage()
29{
30 printOut(out: uR"(
31Usage:
32 lrelease-pro [options] [project-file]...
33lrelease-pro is part of Qt's Linguist tool chain. It extracts project
34information from qmake projects and passes it to lrelease.
35All command line options that are not consumed by lrelease-pro are
36passed to lrelease.
37
38Options:
39 -help Display this information and exit
40 -keep Keep the temporary project dump around
41 -silent
42 Do not explain what is being done
43 -version
44 Display the version of lrelease-pro and exit
45)"_s);
46}
47
48int main(int argc, char **argv)
49{
50 QCoreApplication app(argc, argv);
51#ifndef QT_BOOTSTRAPPED
52#ifndef Q_OS_WIN32
53 QTranslator translator;
54 QTranslator qtTranslator;
55 QString sysLocale = QLocale::system().name();
56 QString resourceDir = QLibraryInfo::path(p: QLibraryInfo::TranslationsPath);
57 if (translator.load(filename: QLatin1String("linguist_") + sysLocale, directory: resourceDir)
58 && qtTranslator.load(filename: QLatin1String("qt_") + sysLocale, directory: resourceDir)) {
59 app.installTranslator(messageFile: &translator);
60 app.installTranslator(messageFile: &qtTranslator);
61 }
62#endif // Q_OS_WIN32
63#endif // QT_BOOTSTRAPPED
64
65 bool keepProjectDescription = false;
66 QStringList inputFiles;
67 QStringList lprodumpOptions;
68 QStringList lreleaseOptions;
69
70 for (int i = 1; i < argc; ++i) {
71 if (!strcmp(s1: argv[i], s2: "-keep")) {
72 keepProjectDescription = true;
73 } else if (!strcmp(s1: argv[i], s2: "-silent")) {
74 const QString arg = QString::fromLocal8Bit(ba: argv[i]);
75 lprodumpOptions << arg;
76 lreleaseOptions << arg;
77 } else if (!strcmp(s1: argv[i], s2: "-version")) {
78 printOut(QStringLiteral("lrelease-pro version %1\n")
79 .arg(a: QLatin1String(QT_VERSION_STR)));
80 return 0;
81 } else if (!strcmp(s1: argv[i], s2: "-help")) {
82 printUsage();
83 return 0;
84 } else if (strlen(s: argv[i]) > 0 && argv[i][0] == '-') {
85 lreleaseOptions << QString::fromLocal8Bit(ba: argv[i]);
86 } else {
87 inputFiles << QString::fromLocal8Bit(ba: argv[i]);
88 }
89 }
90
91 if (inputFiles.isEmpty()) {
92 printUsage();
93 return 1;
94 }
95
96 lprodumpOptions << QStringLiteral("-translations-variables")
97 << QStringLiteral("TRANSLATIONS,EXTRA_TRANSLATIONS");
98
99 const QStringList proFiles = extractProFiles(files: &inputFiles);
100 if (proFiles.isEmpty()) {
101 printErr(out: u"lrelease-pro: No .pro/.pri files given.\n"_s);
102 return 1;
103 }
104 if (!inputFiles.isEmpty()) {
105 printErr(QStringLiteral("lrelease-pro: Only .pro/.pri files are supported. "
106 "Offending files:\n %1\n")
107 .arg(a: inputFiles.join(sep: QLatin1String("\n "))));
108 return 1;
109 }
110
111 lprodumpOptions << proFiles;
112 std::unique_ptr<QTemporaryFile> projectDescription = createProjectDescription(args: lprodumpOptions);
113 if (keepProjectDescription)
114 projectDescription->setAutoRemove(false);
115 lreleaseOptions << QStringLiteral("-project") << projectDescription->fileName();
116
117 runQtTool(QStringLiteral("lrelease"), arguments: lreleaseOptions);
118 return 0;
119}
120

source code of qttools/src/linguist/lrelease-pro/main.cpp