| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Linguist of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <profileutils.h> |
| 30 | #include <runqttool.h> |
| 31 | |
| 32 | #include <QtCore/qcoreapplication.h> |
| 33 | #include <QtCore/qdebug.h> |
| 34 | #include <QtCore/qlibraryinfo.h> |
| 35 | #include <QtCore/qtranslator.h> |
| 36 | |
| 37 | #include <iostream> |
| 38 | |
| 39 | QT_USE_NAMESPACE |
| 40 | |
| 41 | #ifdef QT_BOOTSTRAPPED |
| 42 | struct LR { |
| 43 | static inline QString tr(const char *sourceText, const char *comment = 0) |
| 44 | { |
| 45 | return QCoreApplication::translate("LRelease" , sourceText, comment); |
| 46 | } |
| 47 | }; |
| 48 | #else |
| 49 | class LR { |
| 50 | Q_DECLARE_TR_FUNCTIONS(LRelease) |
| 51 | }; |
| 52 | #endif |
| 53 | |
| 54 | static void printOut(const QString &out) |
| 55 | { |
| 56 | std::cout << qPrintable(out); |
| 57 | } |
| 58 | |
| 59 | static void printErr(const QString &out) |
| 60 | { |
| 61 | std::cerr << qPrintable(out); |
| 62 | } |
| 63 | |
| 64 | static void printUsage() |
| 65 | { |
| 66 | printOut(out: LR::tr( |
| 67 | sourceText: "Usage:\n" |
| 68 | " lrelease-pro [options] [project-file]...\n" |
| 69 | "lrelease-pro is part of Qt's Linguist tool chain. It extracts project\n" |
| 70 | "information from qmake projects and passes it to lrelease.\n" |
| 71 | "All command line options that are not consumed by lrelease-pro are\n" |
| 72 | "passed to lrelease.\n\n" |
| 73 | "Options:\n" |
| 74 | " -help Display this information and exit\n" |
| 75 | " -keep Keep the temporary project dump around\n" |
| 76 | " -silent\n" |
| 77 | " Do not explain what is being done\n" |
| 78 | " -version\n" |
| 79 | " Display the version of lrelease-pro and exit\n" |
| 80 | )); |
| 81 | } |
| 82 | |
| 83 | int main(int argc, char **argv) |
| 84 | { |
| 85 | QCoreApplication app(argc, argv); |
| 86 | #ifndef QT_BOOTSTRAPPED |
| 87 | #ifndef Q_OS_WIN32 |
| 88 | QTranslator translator; |
| 89 | QTranslator qtTranslator; |
| 90 | QString sysLocale = QLocale::system().name(); |
| 91 | QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); |
| 92 | if (translator.load(filename: QLatin1String("linguist_" ) + sysLocale, directory: resourceDir) |
| 93 | && qtTranslator.load(filename: QLatin1String("qt_" ) + sysLocale, directory: resourceDir)) { |
| 94 | app.installTranslator(messageFile: &translator); |
| 95 | app.installTranslator(messageFile: &qtTranslator); |
| 96 | } |
| 97 | #endif // Q_OS_WIN32 |
| 98 | #endif // QT_BOOTSTRAPPED |
| 99 | |
| 100 | bool keepProjectDescription = false; |
| 101 | QStringList inputFiles; |
| 102 | QStringList lprodumpOptions; |
| 103 | QStringList lreleaseOptions; |
| 104 | |
| 105 | for (int i = 1; i < argc; ++i) { |
| 106 | if (!strcmp(s1: argv[i], s2: "-keep" )) { |
| 107 | keepProjectDescription = true; |
| 108 | } else if (!strcmp(s1: argv[i], s2: "-silent" )) { |
| 109 | const QString arg = QString::fromLocal8Bit(str: argv[i]); |
| 110 | lprodumpOptions << arg; |
| 111 | lreleaseOptions << arg; |
| 112 | } else if (!strcmp(s1: argv[i], s2: "-version" )) { |
| 113 | printOut(out: LR::tr(sourceText: "lrelease-pro version %1\n" ).arg(a: QLatin1String(QT_VERSION_STR))); |
| 114 | return 0; |
| 115 | } else if (!strcmp(s1: argv[i], s2: "-help" )) { |
| 116 | printUsage(); |
| 117 | return 0; |
| 118 | } else if (strlen(s: argv[i]) > 0 && argv[i][0] == '-') { |
| 119 | lreleaseOptions << QString::fromLocal8Bit(str: argv[i]); |
| 120 | } else { |
| 121 | inputFiles << QString::fromLocal8Bit(str: argv[i]); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | if (inputFiles.isEmpty()) { |
| 126 | printUsage(); |
| 127 | return 1; |
| 128 | } |
| 129 | |
| 130 | const QStringList proFiles = extractProFiles(files: &inputFiles); |
| 131 | if (proFiles.isEmpty()) { |
| 132 | printErr(out: LR::tr(sourceText: "lrelease-pro: No .pro/.pri files given.\n" )); |
| 133 | return 1; |
| 134 | } |
| 135 | if (!inputFiles.isEmpty()) { |
| 136 | printErr(out: LR::tr(sourceText: "lrelease-pro: Only .pro/.pri files are supported. " |
| 137 | "Offending files:\n %1\n" ) |
| 138 | .arg(a: inputFiles.join(sep: QLatin1String("\n " )))); |
| 139 | return 1; |
| 140 | } |
| 141 | |
| 142 | lprodumpOptions << proFiles; |
| 143 | std::unique_ptr<QTemporaryFile> projectDescription = createProjectDescription(args: lprodumpOptions); |
| 144 | if (keepProjectDescription) |
| 145 | projectDescription->setAutoRemove(false); |
| 146 | lreleaseOptions << QStringLiteral("-project" ) << projectDescription->fileName(); |
| 147 | |
| 148 | runQtTool(QStringLiteral("lrelease" ), arguments: lreleaseOptions); |
| 149 | return 0; |
| 150 | } |
| 151 | |