feat:Added option to use system locale
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -527,34 +527,34 @@ Language * TranslationsModel::findLanguage(const QString& key)
|
||||
}
|
||||
}
|
||||
|
||||
void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
|
||||
{
|
||||
APPLICATION->settings()->set("UseSystemLocales", useSystemLocale);
|
||||
QLocale::setDefault(QLocale(useSystemLocale ? QString::fromStdString(std::locale().name()) : defaultLangCode));
|
||||
}
|
||||
|
||||
bool TranslationsModel::selectLanguage(QString key)
|
||||
{
|
||||
QString &langCode = key;
|
||||
QString& langCode = key;
|
||||
auto langPtr = findLanguage(key);
|
||||
|
||||
if (langCode.isEmpty())
|
||||
{
|
||||
if (langCode.isEmpty()) {
|
||||
d->no_language_set = true;
|
||||
}
|
||||
|
||||
if(!langPtr)
|
||||
{
|
||||
if (!langPtr) {
|
||||
qWarning() << "Selected invalid language" << key << ", defaulting to" << defaultLangCode;
|
||||
langCode = defaultLangCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
langCode = langPtr->key;
|
||||
}
|
||||
|
||||
// uninstall existing translators if there are any
|
||||
if (d->m_app_translator)
|
||||
{
|
||||
if (d->m_app_translator) {
|
||||
QCoreApplication::removeTranslator(d->m_app_translator.get());
|
||||
d->m_app_translator.reset();
|
||||
}
|
||||
if (d->m_qt_translator)
|
||||
{
|
||||
if (d->m_qt_translator) {
|
||||
QCoreApplication::removeTranslator(d->m_qt_translator.get());
|
||||
d->m_qt_translator.reset();
|
||||
}
|
||||
@ -564,8 +564,9 @@ bool TranslationsModel::selectLanguage(QString key)
|
||||
* In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.
|
||||
* This function is not reentrant.
|
||||
*/
|
||||
QLocale locale = QLocale(langCode);
|
||||
QLocale::setDefault(locale);
|
||||
QLocale::setDefault(
|
||||
QLocale(APPLICATION->settings()->get("UseSystemLocales").toBool() ? QString::fromStdString(std::locale().name()) : langCode));
|
||||
|
||||
|
||||
// if it's the default UI language, finish
|
||||
if(langCode == defaultLangCode)
|
||||
|
@ -20,17 +20,16 @@
|
||||
|
||||
struct Language;
|
||||
|
||||
class TranslationsModel : public QAbstractListModel
|
||||
{
|
||||
class TranslationsModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TranslationsModel(QString path, QObject *parent = 0);
|
||||
public:
|
||||
explicit TranslationsModel(QString path, QObject* parent = 0);
|
||||
virtual ~TranslationsModel();
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex & parent) const override;
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex& parent) const override;
|
||||
|
||||
bool selectLanguage(QString key);
|
||||
void updateLanguage(QString key);
|
||||
@ -38,27 +37,27 @@ public:
|
||||
QString selectedLanguage();
|
||||
|
||||
void downloadIndex();
|
||||
void setUseSystemLocale(bool useSystemLocale);
|
||||
|
||||
private:
|
||||
Language *findLanguage(const QString & key);
|
||||
private:
|
||||
Language* findLanguage(const QString& key);
|
||||
void reloadLocalFiles();
|
||||
void downloadTranslation(QString key);
|
||||
void downloadNext();
|
||||
|
||||
// hide copy constructor
|
||||
TranslationsModel(const TranslationsModel &) = delete;
|
||||
TranslationsModel(const TranslationsModel&) = delete;
|
||||
// hide assign op
|
||||
TranslationsModel &operator=(const TranslationsModel &) = delete;
|
||||
TranslationsModel& operator=(const TranslationsModel&) = delete;
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void indexReceived();
|
||||
void indexFailed(QString reason);
|
||||
void dlFailed(QString reason);
|
||||
void dlGood();
|
||||
void translationDirChanged(const QString &path);
|
||||
void translationDirChanged(const QString& path);
|
||||
|
||||
|
||||
private: /* data */
|
||||
private: /* data */
|
||||
struct Private;
|
||||
std::unique_ptr<Private> d;
|
||||
};
|
||||
|
Reference in New Issue
Block a user