Skip to content

Commit

Permalink
Add the "Territory" enumerated type for QLocale
Browse files Browse the repository at this point in the history
The use of "Country" is misleading as some entries in the enumeration
are not countries (eg, HongKong), for all that most are. The Unicode
Consortium's Common Locale Data Repository (CLDR, from which QLocale's
data is taken) calls these territories, so introduce territory-based
names and prepare to deprecate the country-based ones in due course.

[ChangeLog][QtCore][QLocale] QLocale now has Territory as an alias for
its Country enumeration, and associated territory-based names to match
its country-named methods, to better match the usage in relevant
standards. The country-based names shall in due course be deprecated
in favor of the territory-based names.

Fixes: QTBUG-91686
Change-Id: Ia1ae1ad7323867016186fb775c9600cd5113aa42
Reviewed-by: Edward Welbourne <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
JiDe Zhang committed Apr 15, 2021
1 parent 7c8d45c commit 50a7eb8
Show file tree
Hide file tree
Showing 41 changed files with 636 additions and 459 deletions.
11 changes: 5 additions & 6 deletions examples/widgets/widgets/calendarwidget/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,13 @@ void Window::createGeneralOptionsGroupBox()
int index = 0;
for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
QLocale::Language lang = static_cast<QLocale::Language>(_lang);
QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
for (int i = 0; i < countries.count(); ++i) {
QLocale::Country country = countries.at(i);
const auto territories = QLocale::territoriesForLanguage(lang);
for (auto territory : territories) {
QString label = QLocale::languageToString(lang);
label += QLatin1Char('/');
label += QLocale::countryToString(country);
QLocale locale(lang, country);
if (this->locale().language() == lang && this->locale().country() == country)
label += QLocale::territoryToString(territory);
QLocale locale(lang, territory);
if (this->locale().language() == lang && this->locale().territory() == territory)
curLocaleIndex = index;
localeCombo->addItem(label, locale);
++index;
Expand Down
10 changes: 5 additions & 5 deletions examples/widgets/widgets/validators/localeselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ LocaleSelector::LocaleSelector(QWidget *parent)
for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
QLocale::Language lang = static_cast<QLocale::Language>(_lang);
const QList<QLocale> locales =
QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyCountry);
QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyTerritory);
for (const QLocale &l : locales) {
QString label = QLocale::languageToString(l.language());
label += QLatin1Char('/');
label += QLocale::countryToString(l.country());
// distinguish locales by script, if there are more than one script for a language/country pair
if (QLocale::matchingLocales(l.language(), QLocale::AnyScript, l.country()).size() > 1)
label += QLocale::territoryToString(l.territory());
// distinguish locales by script, if there are more than one script for a language/territory pair
if (QLocale::matchingLocales(l.language(), QLocale::AnyScript, l.territory()).size() > 1)
label += QLatin1String(" (") + QLocale::scriptToString(l.script()) + QLatin1Char(')');

addItem(label, QVariant::fromValue(l));

if (l.language() == locale().language() && l.country() == locale().country()
if (l.language() == locale().language() && l.territory() == locale().territory()
&& (locale().script() == QLocale::AnyScript || l.script() == locale().script())) {
curIndex = index;
}
Expand Down
11 changes: 6 additions & 5 deletions src/corelib/io/qresource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
}
}
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << "!!!!" << "START" << path << locale.country() << locale.language();
qDebug() << "!!!!" << "START" << path << locale.territory() << locale.language();
#endif

if (path == QLatin1String("/"))
Expand Down Expand Up @@ -877,22 +877,23 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const

if (!splitter.hasNext()) {
if (!(flags & Directory)) {
const qint16 country = qFromBigEndian<qint16>(tree + offset);
const qint16 territory = qFromBigEndian<qint16>(tree + offset);
offset += 2;

const qint16 language = qFromBigEndian<qint16>(tree + offset);
offset += 2;
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << " " << "LOCALE" << country << language;
#endif
if (country == locale.country() && language == locale.language()) {
if (territory == locale.territory() && language == locale.language()) {
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node;
#endif
return sub_node;
} else if ((country == QLocale::AnyCountry
} else if ((territory == QLocale::AnyTerritory
&& language == locale.language())
|| (country == QLocale::AnyCountry && language == QLocale::C
|| (territory == QLocale::AnyTerritory
&& language == QLocale::C
&& node == -1)) {
node = sub_node;
}
Expand Down
Loading

0 comments on commit 50a7eb8

Please sign in to comment.