Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve translation loading #3826

Merged
merged 8 commits into from
May 14, 2021
Prev Previous commit
Next Next commit
Translations: Simplify code (remove scope and redundant default constrs)
Holzhaus committed May 4, 2021
commit 8c45a70fa405bac7db17d646049cbc3e4a8dcc7d
49 changes: 25 additions & 24 deletions src/util/translations.h
Original file line number Diff line number Diff line change
@@ -21,35 +21,36 @@ class Translations {
// Set the default locale, if specified via command line or config
// file. If neither is the case, the default locale will be the
// system's locale.
{
QString customLocaleString = QString();
if (!cmdlineLocaleString.isEmpty()) {
customLocaleString = cmdlineLocaleString;
} else {
const QString configLocale = pConfig->getValueString(
ConfigKey("[Config]", "Locale"));
if (!configLocale.isEmpty()) {
customLocaleString = configLocale;
}
QString customLocaleString;
if (!cmdlineLocaleString.isEmpty()) {
customLocaleString = cmdlineLocaleString;
} else {
const QString configLocale = pConfig->getValueString(
ConfigKey("[Config]", "Locale"));
if (!configLocale.isEmpty()) {
customLocaleString = configLocale;
}
}

if (!customLocaleString.isEmpty()) {
const QLocale customLocale = QLocale(customLocaleString);
// If the customLocaleString is not a valid locale, Qt will
// automatically use the "C" locale instead. In that case,
// let's print a warning.
if (customLocaleString.compare(
QStringLiteral("C"), Qt::CaseInsensitive) != 0 &&
customLocale.language() == QLocale::C) {
qWarning() << "Custom locale not found, using 'C' locale "
"(check your configuration to avoid this "
"warning).";
}
QLocale::setDefault(customLocale);
if (!customLocaleString.isEmpty()) {
const QLocale customLocale = QLocale(customLocaleString);
// If the customLocaleString is not a valid locale, Qt will
// automatically use the "C" locale instead. In that case,
// let's print a warning.
if (customLocaleString.compare(
QStringLiteral("C"), Qt::CaseInsensitive) != 0 &&
customLocale.language() == QLocale::C) {
qWarning() << "Custom locale not found, using 'C' locale "
"(check your configuration to avoid this "
"warning).";
}
QLocale::setDefault(customLocale);
}

QLocale locale = QLocale();
// Constructs a QLocale object initialized with the default locale. If
// no default locale was set using setDefault(), this locale will be
// the same as the one returned by system().
QLocale locale;

// Do not try to load translations if we're using 'C' locale.
if (locale.language() == QLocale::C) {