8#include <QJsonDocument>
14#include <unordered_map>
21 for (
const auto &
item : jsonArray) {
43 std::wcerr <<
"Trying to read translation catalogs from \""
54 *errorString = jsonParseError.errorString();
58 if (!document.isArray()) {
71 catalogs.emplace_back(std::move(catalog));
88 *errorString = jsonParseError.errorString();
92 if (!document.isObject()) {
99 module.name = "Qt6"_L1 + obj[QLatin1String("name")].toString();
100 module.repository = obj[QLatin1String("repository")].toString();
101 module.internal = obj[QLatin1String("internal")].toBool();
102 module.pluginTypes = toStringList(obj[QLatin1String("plugin_types")].toArray());
110 qDebug().nospace() <<
" plugin types: " <<
module.pluginTypes;
112 qDebug().nospace() <<
" translation catalog: "<<
module.translationCatalog;
116 bool verbose,
QString *errorString)
120 if (!errorString->isEmpty()) {
121 std::wcerr <<
"Warning: Translations will not be available due to the following error."
122 << std::endl << *errorString << std::endl;
123 errorString->clear();
125 std::unordered_map<QString, QString> moduleToCatalogMap;
126 std::unordered_map<QString, QString> repositoryToCatalogMap;
128 for (
const QString &module : catalog.modules) {
129 moduleToCatalogMap.insert(std::make_pair(module, catalog.name));
131 for (
const QString &repository : catalog.repositories) {
132 repositoryToCatalogMap.insert(std::make_pair(repository, catalog.name));
138 QtModule module = moduleFromJsonFile(dirEntry.filePath(), errorString);
139 if (!errorString->isEmpty())
141 if (module.internal && module.name.endsWith(
QStringLiteral(
"Private")))
143 module.id = modules.size();
145 *errorString =
"Internal Error: too many modules for ModuleBitset to hold."_L1;
150 auto it = moduleToCatalogMap.
find(module.name);
151 if (
it != moduleToCatalogMap.
end())
152 module.translationCatalog =
it->second;
154 if (module.translationCatalog.isEmpty()) {
155 auto it = repositoryToCatalogMap.
find(module.repository);
156 if (
it != repositoryToCatalogMap.
end())
157 module.translationCatalog = it->second;
161 modules.emplace_back(std::move(module));
169 return modules.at(
id);
174 auto moduleHasPluginType = [&pluginType] (
const QtModule &module) {
175 return module.pluginTypes.contains(pluginType);
178 auto it = std::find_if(modules.begin(), modules.end(), moduleHasPluginType);
179 if (
it != modules.end())
The QDirListing class provides an STL-style iterator for directory entries.
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QString fileName() const override
Returns the name set by setFileName() or to the QFile constructors.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
\inmodule QtCore\reentrant
\inmodule QtCore \reentrant
iterator find(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
void chop(qsizetype n)
Removes n characters from the end of the string.
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
bool populate(const QString &modulesDir, const QString &translationsDir, bool verbose, QString *errorString)
const QtModule & moduleById(size_t id) const
size_t moduleIdForPluginType(const QString &pluginType) const
QSet< QString >::iterator it
static QString dump(const QByteArray &)
#define qUtf8Printable(string)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static QtModule moduleFromJsonFile(const QString &filePath, QString *errorString)
std::vector< TranslationCatalog > TranslationCatalogs
static TranslationCatalogs readTranslationsCatalogs(const QString &translationsDir, bool verbose, QString *errorString)
static QStringList toStringList(const QJsonArray &jsonArray)
static void dump(const QtModule &module)
\inmodule QtCore\reentrant
static constexpr size_t InvalidId
QString translationCatalog