Fix locale look-up when language is unspecified

Looking up a locale with unspecified language got the C locale, due to
taking a short-cut that would make sense if no locale were found for a
specified language. Stop assuming the language was specified.

Task-number: QTBUG-74287
Change-Id: I8b3c232da584fb187ebb6c190729c377d0083808
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit e69b81101c6e09d1c1b81d50ea868a8625c9f248)
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
This commit is contained in:
Edward Welbourne 2020-10-15 17:25:24 +02:00
parent 36c7513106
commit 5b96d64dce

View File

@ -361,10 +361,14 @@ static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
const QLocaleData *data = locale_data + idx;
if (idx == 0) // default language has no associated script or country
// If there are no locales for specified language (so we we've got the
// default language, which has no associated script or country), give up:
if (localeId.language_id && idx == 0)
return data;
Q_ASSERT(data->m_language_id == localeId.language_id);
Q_ASSERT(localeId.language_id
? data->m_language_id == localeId.language_id
: data->m_language_id);
if (localeId.script_id == QLocale::AnyScript && localeId.country_id == QLocale::AnyCountry)
return data;
@ -374,19 +378,25 @@ static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
if (data->m_country_id == localeId.country_id)
return data;
++data;
} while (data->m_language_id && data->m_language_id == localeId.language_id);
} while (localeId.language_id
? data->m_language_id == localeId.language_id
: data->m_language_id);
} else if (localeId.country_id == QLocale::AnyCountry) {
do {
if (data->m_script_id == localeId.script_id)
return data;
++data;
} while (data->m_language_id && data->m_language_id == localeId.language_id);
} while (localeId.language_id
? data->m_language_id == localeId.language_id
: data->m_language_id);;
} else {
do {
if (data->m_script_id == localeId.script_id && data->m_country_id == localeId.country_id)
return data;
++data;
} while (data->m_language_id && data->m_language_id == localeId.language_id);
} while (localeId.language_id
? data->m_language_id == localeId.language_id
: data->m_language_id);;
}
return 0;