Allow tracking whether the locale has changed via the `QtSettings` class

This allows an application to reload translations if the default locale has
changed to apply locale changes dynamically.
This commit is contained in:
Martchus 2023-07-02 23:48:46 +02:00
parent f30d020cda
commit f69ffec06c
2 changed files with 11 additions and 0 deletions

View File

@ -50,6 +50,7 @@ struct QtSettingsData {
QString iconTheme;
QString initialIconTheme;
QLocale defaultLocale;
QLocale previousLocale;
QString localeName;
QString previousPluginDirectory;
QString additionalPluginDirectory;
@ -319,6 +320,7 @@ void QtSettings::apply()
}
// apply locale
m_d->previousLocale = QLocale();
QLocale::setDefault(m_d->customLocale ? QLocale(m_d->localeName) : m_d->defaultLocale);
}
@ -355,6 +357,14 @@ bool QtSettings::isPaletteDark()
return m_d->isPaletteDark;
}
/*!
* \brief Returns whether the last apply() call has changed the default locale.
*/
bool QtSettings::hasLocaleChanged() const
{
return m_d->previousLocale != QLocale();
}
/*!
* \brief Returns a new OptionCatecory containing all Qt related option pages.
* \remarks

View File

@ -53,6 +53,7 @@ public:
void reevaluatePaletteAndDefaultIconTheme();
bool isPaletteDark();
bool hasCustomFont() const;
bool hasLocaleChanged() const;
operator QtSettingsData &() const;
OptionCategory *category();