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)
|
||||
|
Reference in New Issue
Block a user