mirror of
https://github.com/GerbilSoft/rvthtool.git
synced 2025-06-18 19:45:35 -04:00
[qrvthtool] TranslationManager: Also load qtbase_*.qm.
qtbase_*.qm has some POSIX error codes, which still need to be handled properly in qrvthtool.
This commit is contained in:
parent
8d34c3e3dd
commit
35505dc1ed
@ -10,7 +10,7 @@
|
|||||||
#include "TranslationManager.hpp"
|
#include "TranslationManager.hpp"
|
||||||
#include "config/ConfigStore.hpp"
|
#include "config/ConfigStore.hpp"
|
||||||
|
|
||||||
// Qt includes.
|
// Qt includes
|
||||||
#include <QtCore/QTranslator>
|
#include <QtCore/QTranslator>
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
#include <QtCore/QVector>
|
#include <QtCore/QVector>
|
||||||
@ -18,6 +18,10 @@
|
|||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QLibraryInfo>
|
#include <QtCore/QLibraryInfo>
|
||||||
|
|
||||||
|
// C++ STL classes
|
||||||
|
#include <array>
|
||||||
|
using std::array;
|
||||||
|
|
||||||
/** TranslationManagerPrivate **/
|
/** TranslationManagerPrivate **/
|
||||||
|
|
||||||
class TranslationManagerPrivate
|
class TranslationManagerPrivate
|
||||||
@ -133,35 +137,42 @@ void TranslationManager::setTranslation(const QString &locale)
|
|||||||
Q_D(TranslationManager);
|
Q_D(TranslationManager);
|
||||||
|
|
||||||
// Initialize the Qt translation system.
|
// Initialize the Qt translation system.
|
||||||
QString qtLocale = QStringLiteral("qt_") + locale;
|
const array<QString, 2> qtLocales = {
|
||||||
bool isQtSysTranslator = false;
|
QStringLiteral("qt_") + locale,
|
||||||
|
QStringLiteral("qtbase_") + locale,
|
||||||
|
};
|
||||||
|
array<bool, 2> isLoaded = {false, false};
|
||||||
|
|
||||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
||||||
// Qt on Unix (but not Mac) is usually installed system-wide.
|
// Qt on Unix (but not Mac) is usually installed system-wide.
|
||||||
// Check the Qt library path first.
|
// Check the Qt library path first.
|
||||||
|
for (size_t i = 0; i < qtLocales.size(); i++) {
|
||||||
# if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
# if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||||
isQtSysTranslator = d->qtTranslator->load(qtLocale,
|
auto path = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
|
||||||
QLibraryInfo::path(QLibraryInfo::TranslationsPath));
|
|
||||||
# else /* QT_VERSION < QT_VERSION_CHECK(6,0,0) */
|
# else /* QT_VERSION < QT_VERSION_CHECK(6,0,0) */
|
||||||
isQtSysTranslator = d->qtTranslator->load(qtLocale,
|
auto path = QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
||||||
# endif /* QT_VERSION >= QT_VERSION_CHECK(6,0,0) */
|
# endif /* QT_VERSION >= QT_VERSION_CHECK(6,0,0) */
|
||||||
#else
|
isLoaded[i] = d->qtTranslator->load(qtLocales[i], path);
|
||||||
// Suppress warnings that isQtSysTranslator is used but not set.
|
}
|
||||||
Q_UNUSED(isQtSysTranslator)
|
|
||||||
#endif
|
#endif
|
||||||
if (!isQtSysTranslator) {
|
|
||||||
|
if (!isLoaded[0] || !isLoaded[1]) {
|
||||||
// System-wide translations aren't installed.
|
// System-wide translations aren't installed.
|
||||||
// Check other paths.
|
// Check other paths.
|
||||||
foreach (const QString &path, d->pathList) {
|
for (const QString &path : d->pathList) {
|
||||||
if (d->qtTranslator->load(qtLocale, path)) {
|
for (size_t i = 0; i < qtLocales.size(); i++) {
|
||||||
break;
|
if (isLoaded[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoaded[i] = d->qtTranslator->load(qtLocales[i], path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the application translator.
|
// Initialize the application translator.
|
||||||
QString prgLocale = QStringLiteral("rvthtool_") + locale;
|
QString prgLocale = QStringLiteral("rvthtool_") + locale;
|
||||||
foreach (const QString &path, d->pathList) {
|
for (const QString &path : d->pathList) {
|
||||||
if (d->prgTranslator->load(prgLocale, path)) {
|
if (d->prgTranslator->load(prgLocale, path)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -192,21 +203,20 @@ QMap<QString, QString> TranslationManager::enumerate(void) const
|
|||||||
// Name filters.
|
// Name filters.
|
||||||
// Remember that compiled translations have the
|
// Remember that compiled translations have the
|
||||||
// extension *.qm, not *.ts.
|
// extension *.qm, not *.ts.
|
||||||
static const char nameFilters_c[4][5] = {
|
const QStringList nameFilters = {
|
||||||
"*.qm", "*.qM", "*.Qm", "*.QM",
|
QLatin1String("*.qm"),
|
||||||
|
QLatin1String("*.qM"),
|
||||||
|
QLatin1String("*.Qm"),
|
||||||
|
QLatin1String("*.QM"),
|
||||||
};
|
};
|
||||||
|
|
||||||
QStringList nameFilters;
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
nameFilters << QLatin1String(nameFilters_c[i]);
|
|
||||||
|
|
||||||
// Search the paths for TS files.
|
// Search the paths for TS files.
|
||||||
static constexpr QDir::Filters filters = (QDir::Files | QDir::Readable);
|
static constexpr QDir::Filters filters = (QDir::Files | QDir::Readable);
|
||||||
|
|
||||||
Q_D(const TranslationManager);
|
Q_D(const TranslationManager);
|
||||||
QMap<QString, QString> tsMap;
|
QMap<QString, QString> tsMap;
|
||||||
QTranslator tmpTs;
|
QTranslator tmpTs;
|
||||||
foreach (const QString &path, d->pathList) {
|
for (const QString &path : d->pathList) {
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
QFileInfoList files = dir.entryInfoList(nameFilters, filters);
|
QFileInfoList files = dir.entryInfoList(nameFilters, filters);
|
||||||
foreach (const QFileInfo &file, files) {
|
foreach (const QFileInfo &file, files) {
|
||||||
|
Loading…
Reference in New Issue
Block a user