mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-05-02 12:39:41 +00:00
parent
4c596e3088
commit
76482dd08f
26
locales.cpp
26
locales.cpp
@ -12,21 +12,35 @@
|
||||
#include <QTranslator>
|
||||
#include <QLocale>
|
||||
#include <QLibraryInfo>
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
#include <QLibraryInfo>
|
||||
#include "params.h"
|
||||
|
||||
using namespace QuasarAppUtils;
|
||||
|
||||
bool Locales::setLocalePrivate(const QLocale &locale) {
|
||||
removeOldTranslation();
|
||||
QFileInfoList qmFiles;
|
||||
bool QuasarAppUtils::Locales::findQm(const QString& localePrefix,
|
||||
QFileInfoList &qmFiles) {
|
||||
|
||||
for (const auto &location: qAsConst(_locations)) {
|
||||
qmFiles += QDir(location).entryInfoList({"*" + locale.bcp47Name() + "*.qm"}, QDir::Files);
|
||||
qmFiles += QDir(location).entryInfoList({"*" + localePrefix + "*.qm"}, QDir::Files);
|
||||
}
|
||||
|
||||
return qmFiles.size();
|
||||
}
|
||||
|
||||
bool Locales::setLocalePrivate(const QLocale &locale) {
|
||||
removeOldTranslation();
|
||||
|
||||
const auto list = locale.uiLanguages();
|
||||
QFileInfoList qmFiles;
|
||||
|
||||
auto it = list.begin();
|
||||
while (it != list.end() && !findQm(*it, qmFiles)) {
|
||||
it++;
|
||||
}
|
||||
|
||||
if (qmFiles.isEmpty())
|
||||
return false;
|
||||
|
||||
for (const auto & file: qAsConst(qmFiles)) {
|
||||
auto translator = new QTranslator();
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <QLocale>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
|
||||
class QCoreApplication;
|
||||
class QTranslator;
|
||||
@ -90,6 +91,9 @@ private:
|
||||
|
||||
const QLocale ¤tLocatePrivate() const;
|
||||
|
||||
bool findQm(const QString &localePrefix,
|
||||
QFileInfoList& result);
|
||||
|
||||
QLocale _currentLocate;
|
||||
QSet<QString> _locations;
|
||||
QList<QTranslator *> _translations;
|
||||
|
Loading…
x
Reference in New Issue
Block a user