diff options
author | JiDe Zhang <zhangjide@uniontech.com> | 2021-03-09 16:19:54 +0800 |
---|---|---|
committer | JiDe Zhang <zhangjide@uniontech.com> | 2021-04-15 20:17:49 +0800 |
commit | 50a7eb8cf75a2f9cebde6d0d23c108e5e7f1870b (patch) | |
tree | c947e4746bb55f723c4005534cb98501f083036a /util | |
parent | 7c8d45cb2635ab44d85d85288fd74ef72909264c (diff) |
Add the "Territory" enumerated type for QLocale
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 <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/locale_database/cldr.py | 4 | ||||
-rw-r--r-- | util/locale_database/enumdata.py | 8 | ||||
-rw-r--r-- | util/locale_database/qlocalexml.py | 6 | ||||
-rwxr-xr-x | util/locale_database/qlocalexml2cpp.py | 24 | ||||
-rw-r--r-- | util/locale_database/testlocales/localemodel.cpp | 8 | ||||
-rw-r--r-- | util/xkbdatagen/main.cpp | 4 |
6 files changed, 36 insertions, 18 deletions
diff --git a/util/locale_database/cldr.py b/util/locale_database/cldr.py index f2b6616fce..9b08d8a652 100644 --- a/util/locale_database/cldr.py +++ b/util/locale_database/cldr.py @@ -87,7 +87,7 @@ class CldrReader (object): give = (give[0], # Substitute according to http://www.unicode.org/reports/tr35/#Likely_Subtags have[1] if give[1] == 'AnyScript' else give[1], - have[2] if give[2] == 'AnyCountry' else give[2], + have[2] if give[2] == 'AnyTerritory' else give[2], give[3]) # AnyVariant similarly ? yield have, give @@ -676,7 +676,7 @@ enumdata.py (keeping the old name as an alias): from enumdata import language_list, script_list, country_list for form, book, empty in (('language', language_list, 'AnyLanguage'), ('script', script_list, 'AnyScript'), - ('country', country_list, 'AnyCountry')): + ('country', country_list, 'AnyTerritory')): cache[form] = dict((pair[1], (num, pair[0])) for num, pair in book.items() if pair[0] != 'C') # (Have to filter out the C locale, as we give it the diff --git a/util/locale_database/enumdata.py b/util/locale_database/enumdata.py index ab0f4a3eae..4181e290ac 100644 --- a/util/locale_database/enumdata.py +++ b/util/locale_database/enumdata.py @@ -409,7 +409,7 @@ language_aliases = { } country_list = { - 0: ("AnyCountry", "ZZ"), + 0: ("AnyTerritory", "ZZ"), 1: ("Afghanistan", "AF"), 2: ("Aland Islands", "AX"), @@ -700,6 +700,12 @@ country_aliases = { 'UnitedStatesMinorOutlyingIslands': 'UnitedStatesOutlyingIslands', 'CuraSao': 'Curacao', 'CzechRepublic': 'Czechia', + + # Backwards compatibility with old Country enum, prior to Qt 6.2: + 'AnyCountry': 'AnyTerritory', + 'NauruCountry': 'NauruTerritory', + 'TokelauCountry': 'TokelauTerritory', + 'TuvaluCountry': 'TuvaluTerritory', } script_list = { diff --git a/util/locale_database/qlocalexml.py b/util/locale_database/qlocalexml.py index e5aadba995..4fcfe32a43 100644 --- a/util/locale_database/qlocalexml.py +++ b/util/locale_database/qlocalexml.py @@ -155,7 +155,7 @@ class QLocaleXmlReader (object): try: to = likely[(locale.language, 'AnyScript', locale.country)] except KeyError: - to = likely[(locale.language, 'AnyScript', 'AnyCountry')] + to = likely[(locale.language, 'AnyScript', 'AnyTerritory')] except KeyError: pass else: @@ -196,7 +196,7 @@ class QLocaleXmlReader (object): sub-tags mapping says language's default locale uses the given script and country.""" for have, give in self.__likely: - if have[1:] == ('AnyScript', 'AnyCountry') and give[2] != 'AnyCountry': + if have[1:] == ('AnyScript', 'AnyTerritory') and give[2] != 'AnyTerritory': assert have[0] == give[0], (have, give) yield ((self.__langByName[give[0]][0], self.__textByName[give[1]][0]), @@ -590,7 +590,7 @@ class Locale (object): return cls(cls.__monthNames(calendars), language='C', language_code='0', languageEndonym='', script='AnyScript', script_code='0', - country='AnyCountry', country_code='0', countryEndonym='', + country='AnyTerritory', country_code='0', countryEndonym='', groupSizes=(3, 3, 1), decimal='.', group=',', list=';', percent='%', zero='0', minus='-', plus='+', exp='e', diff --git a/util/locale_database/qlocalexml2cpp.py b/util/locale_database/qlocalexml2cpp.py index 1483545ce7..c15d6d2f55 100755 --- a/util/locale_database/qlocalexml2cpp.py +++ b/util/locale_database/qlocalexml2cpp.py @@ -394,7 +394,7 @@ class LocaleDataWriter (LocaleSourceEditor): self.__writeNameData(self.writer.write, scripts, 'script') def countryNames(self, countries): - self.__writeNameData(self.writer.write, countries, 'country') + self.__writeNameData(self.writer.write, countries, 'territory') # TODO: unify these next three into the previous three; kept # separate for now to verify we're not changing data. @@ -406,7 +406,7 @@ class LocaleDataWriter (LocaleSourceEditor): self.__writeCodeList(self.writer.write, scripts, 'script', 4) def countryCodes(self, countries): # TODO: unify with countryNames() - self.__writeCodeList(self.writer.write, countries, 'country', 3) + self.__writeCodeList(self.writer.write, countries, 'territory', 3) class CalendarDataWriter (LocaleSourceEditor): formatCalendar = ( @@ -469,7 +469,8 @@ class LocaleHeaderWriter (SourceFileEditor): self.writer.write('\n') def countries(self, countries): - self.__enum('Country', countries, self.__country) + self.writer.write(" // ### Qt 7: Rename to Territory\n") + self.__enum('Country', countries, self.__country, 'Territory') def scripts(self, scripts): self.__enum('Script', scripts, self.__script) @@ -480,8 +481,12 @@ class LocaleHeaderWriter (SourceFileEditor): country_aliases as __country, script_aliases as __script) - def __enum(self, name, book, alias): + def __enum(self, name, book, alias, suffix = None): assert book + + if suffix is None: + suffix = name + out, dupes = self.writer.write, self.__dupes out(' enum {} : ushort {{\n'.format(name)) for key, value in book.items(): @@ -495,13 +500,20 @@ class LocaleHeaderWriter (SourceFileEditor): raise Error('The script name "{}" is messy'.format(member)) else: member = ''.join(member.split()) - member = member + name if member in dupes else member + member = member + suffix if member in dupes else member out(' {} = {},\n'.format(member, key)) out('\n ' + ',\n '.join('{} = {}'.format(*pair) for pair in sorted(alias.items())) - + ',\n\n Last{} = {}\n }};\n'.format(name, member)) + + ',\n\n Last{} = {}'.format(suffix, member)) + + # for "LastCountry = LastTerritory" + # ### Qt 7: Remove + if suffix != name: + out(',\n Last{} = Last{}'.format(name, suffix)) + + out('\n };\n') def usage(name, err, message = ''): err.write("""Usage: {} path/to/qlocale.xml root/of/qtbase diff --git a/util/locale_database/testlocales/localemodel.cpp b/util/locale_database/testlocales/localemodel.cpp index d380d01e09..d171bc9855 100644 --- a/util/locale_database/testlocales/localemodel.cpp +++ b/util/locale_database/testlocales/localemodel.cpp @@ -36,11 +36,11 @@ static const int g_model_cols = 6; struct LocaleListItem { int language; - int country; + int territory; }; const LocaleListItem g_locale_list[] = { - { 1, 0 }, // C/AnyCountry + { 1, 0 }, // C/AnyTerritory { 3, 69 }, // Afan/Ethiopia { 3, 111 }, // Afan/Kenya { 4, 59 }, // Afar/Djibouti @@ -317,7 +317,7 @@ QVariant LocaleModel::data(const QModelIndex &index, int role) const locale = QLocale::system(); } else { LocaleListItem item = g_locale_list[index.row() - 2]; - locale = QLocale((QLocale::Language)item.language, (QLocale::Country)item.country); + locale = QLocale((QLocale::Language)item.language, (QLocale::Territory)item.territory); } switch (index.column()) { @@ -386,7 +386,7 @@ QVariant LocaleModel::headerData(int section, Qt::Orientation orientation, int r LocaleListItem item = g_locale_list[section - 2]; return QLocale::languageToString((QLocale::Language)item.language) + QLatin1Char('/') - + QLocale::countryToString((QLocale::Country)item.country); + + QLocale::territoryToString((QLocale::Territory)item.territory); } } diff --git a/util/xkbdatagen/main.cpp b/util/xkbdatagen/main.cpp index 4eba2d8a54..d0b96b78d3 100644 --- a/util/xkbdatagen/main.cpp +++ b/util/xkbdatagen/main.cpp @@ -450,7 +450,7 @@ int main(int argc, char **argv) " const char *variant; // 0 means any variant\n" " Qt::LayoutDirection direction;\n" " QLocale::Language language;\n" - " QLocale::Country country;\n" + " QLocale::Territory territory;\n" "} xkbLayoutData[] = {\n"); // contents @@ -485,7 +485,7 @@ int main(int argc, char **argv) } // wrapping up - printf(" { 0, 0, Qt::LeftToRight, QLocale::C, QLocale::AnyCountry }\n" + printf(" { 0, 0, Qt::LeftToRight, QLocale::C, QLocale::AnyTerritory }\n" "};\n"); return 0; |