Nomenclature change: s/countr/territor/g in locale scripts

Change the nomenclature used in the scripts and the QLocaleXML data
format to use "territory" and "territories" in place of "country" and
"countries". Does not change the generated source files.

Change-Id: I4b208d8d01ad2bfc70d289fa6551f7e0355df5ef
Reviewed-by: JiDe Zhang <zhangjide@uniontech.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2021-05-04 13:20:32 +02:00
parent 21e0ef3ccf
commit e51831260a
7 changed files with 103 additions and 103 deletions

View File

@ -67,7 +67,7 @@ class CldrReader (object):
Yields pairs (have, give) of 4-tuples; if what you have Yields pairs (have, give) of 4-tuples; if what you have
matches the left member, giving the right member is probably matches the left member, giving the right member is probably
sensible. Each 4-tuple's entries are the full names of a sensible. Each 4-tuple's entries are the full names of a
language, a script, a country (strictly territory) and a language, a script, a territory (usually a country) and a
variant (currently ignored).""" variant (currently ignored)."""
skips = [] skips = []
for got, use in self.root.likelySubTags(): for got, use in self.root.likelySubTags():
@ -100,7 +100,7 @@ class CldrReader (object):
def readLocales(self, calendars = ('gregorian',)): def readLocales(self, calendars = ('gregorian',)):
locales = tuple(self.__allLocales(calendars)) locales = tuple(self.__allLocales(calendars))
return dict(((k.language_id, k.script_id, k.country_id, k.variant_code), return dict(((k.language_id, k.script_id, k.territory_id, k.variant_code),
k) for k in locales) k) for k in locales)
def __allLocales(self, calendars): def __allLocales(self, calendars):
@ -109,38 +109,38 @@ class CldrReader (object):
for locale in self.root.defaultContentLocales: for locale in self.root.defaultContentLocales:
try: try:
language, script, country, variant = self.__splitLocale(locale) language, script, territory, variant = self.__splitLocale(locale)
except ValueError: except ValueError:
self.whitter(skip(locale, 'only language tag')) self.whitter(skip(locale, 'only language tag'))
continue continue
if not (script or country): if not (script or territory):
self.grumble(skip(locale, 'second tag is neither script nor territory')) self.grumble(skip(locale, 'second tag is neither script nor territory'))
continue continue
if not (language and country): if not (language and territory):
continue continue
try: try:
yield self.__getLocaleData(self.root.locale(locale), calendars, yield self.__getLocaleData(self.root.locale(locale), calendars,
language, script, country, variant) language, script, territory, variant)
except Error as e: except Error as e:
self.grumble(skip(locale, e.message)) self.grumble(skip(locale, e.message))
for locale in self.root.fileLocales: for locale in self.root.fileLocales:
try: try:
chain = self.root.locale(locale) chain = self.root.locale(locale)
language, script, country, variant = chain.tagCodes() language, script, territory, variant = chain.tagCodes()
assert language assert language
# TODO: this skip should probably be based on likely # TODO: this skip should probably be based on likely
# sub-tags, instead of empty country: if locale has a # sub-tags, instead of empty territory: if locale has a
# likely-subtag expansion, that's what QLocale uses, # likely-subtag expansion, that's what QLocale uses,
# and we'll be saving its data for the expanded locale # and we'll be saving its data for the expanded locale
# anyway, so don't need to record it for itself. # anyway, so don't need to record it for itself.
# See also QLocaleXmlReader.loadLocaleMap's grumble. # See also QLocaleXmlReader.loadLocaleMap's grumble.
if not country: if not territory:
continue continue
yield self.__getLocaleData(chain, calendars, language, script, country, variant) yield self.__getLocaleData(chain, calendars, language, script, territory, variant)
except Error as e: except Error as e:
self.grumble('Skipping file locale "{}" ({})\n'.format(locale, e.message)) self.grumble('Skipping file locale "{}" ({})\n'.format(locale, e.message))
@ -154,12 +154,12 @@ class CldrReader (object):
def __parseTags(self, locale): def __parseTags(self, locale):
tags = self.__splitLocale(locale) tags = self.__splitLocale(locale)
language = tags.next() language = tags.next()
script = country = variant = '' script = territory = variant = ''
try: try:
script, country, variant = tags script, territory, variant = tags
except ValueError: except ValueError:
pass pass
return tuple(p[1] for p in self.root.codesToIdName(language, script, country, variant)) return tuple(p[1] for p in self.root.codesToIdName(language, script, territory, variant))
def __splitLocale(self, name): def __splitLocale(self, name):
"""Generate (language, script, territory, variant) from a locale name """Generate (language, script, territory, variant) from a locale name
@ -206,16 +206,16 @@ class CldrReader (object):
tag = tags.next() tag = tags.next()
self.grumble('Ignoring unparsed cruft {} in {}\n'.format('_'.join(tag + tuple(tags)), name)) self.grumble('Ignoring unparsed cruft {} in {}\n'.format('_'.join(tag + tuple(tags)), name))
def __getLocaleData(self, scan, calendars, language, script, country, variant): def __getLocaleData(self, scan, calendars, language, script, territory, variant):
ids, names = zip(*self.root.codesToIdName(language, script, country, variant)) ids, names = zip(*self.root.codesToIdName(language, script, territory, variant))
assert ids[0] > 0 and ids[2] > 0, (language, script, country, variant) assert ids[0] > 0 and ids[2] > 0, (language, script, territory, variant)
locale = Locale( locale = Locale(
language = names[0], language_code = language, language_id = ids[0], language = names[0], language_code = language, language_id = ids[0],
script = names[1], script_code = script, script_id = ids[1], script = names[1], script_code = script, script_id = ids[1],
country = names[2], country_code = country, country_id = ids[2], territory = names[2], territory_code = territory, territory_id = ids[2],
variant_code = variant) variant_code = variant)
firstDay, weStart, weEnd = self.root.weekData(country) firstDay, weStart, weEnd = self.root.weekData(territory)
assert all(day in ('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun') assert all(day in ('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
for day in (firstDay, weStart, weEnd)) for day in (firstDay, weStart, weEnd))
@ -223,7 +223,7 @@ class CldrReader (object):
weekendStart = weStart, weekendStart = weStart,
weekendEnd = weEnd) weekendEnd = weEnd)
iso, digits, rounding = self.root.currencyData(country) iso, digits, rounding = self.root.currencyData(territory)
locale.update(currencyIsoCode = iso, locale.update(currencyIsoCode = iso,
currencyDigits = int(digits), currencyDigits = int(digits),
currencyRounding = int(rounding)) currencyRounding = int(rounding))
@ -231,7 +231,7 @@ class CldrReader (object):
locale.update(scan.currencyData(iso)) locale.update(scan.currencyData(iso))
locale.update(scan.numericData(self.root.numberSystem, self.whitter)) locale.update(scan.numericData(self.root.numberSystem, self.whitter))
locale.update(scan.textPatternData()) locale.update(scan.textPatternData())
locale.update(scan.endonyms(language, script, country, variant)) locale.update(scan.endonyms(language, script, territory, variant))
locale.update(scan.unitData()) # byte, kB, MB, GB, ..., KiB, MiB, GiB, ... locale.update(scan.unitData()) # byte, kB, MB, GB, ..., KiB, MiB, GiB, ...
locale.update(scan.calendarNames(calendars)) # Names of days and months locale.update(scan.calendarNames(calendars)) # Names of days and months
@ -312,36 +312,36 @@ class CldrAccess (object):
except KeyError: except KeyError:
raise Error('Unsupported number system: {}'.format(system)) raise Error('Unsupported number system: {}'.format(system))
def weekData(self, country): def weekData(self, territory):
"""Data on the weekly cycle. """Data on the weekly cycle.
Returns a triple (W, S, E) of en's short names for week-days; Returns a triple (W, S, E) of en's short names for week-days;
W is the first day of the week, S the start of the week-end W is the first day of the week, S the start of the week-end
and E the end of the week-end. Where data for a country is and E the end of the week-end. Where data for a territory is
unavailable, the data for CLDR's territory 001 (The World) is unavailable, the data for CLDR's territory 001 (The World) is
used.""" used."""
try: try:
return self.__weekData[country] return self.__weekData[territory]
except KeyError: except KeyError:
return self.__weekData['001'] return self.__weekData['001']
def currencyData(self, country): def currencyData(self, territory):
"""Returns currency data for the given country code. """Returns currency data for the given territory code.
Return value is a tuple (ISO4217 code, digit count, rounding Return value is a tuple (ISO4217 code, digit count, rounding
mode). If CLDR provides no data for this country, ('', 2, 1) mode). If CLDR provides no data for this territory, ('', 2, 1)
is the default result. is the default result.
""" """
try: try:
return self.__currencyData[country] return self.__currencyData[territory]
except KeyError: except KeyError:
return '', 2, 1 return '', 2, 1
def codesToIdName(self, language, script, country, variant = ''): def codesToIdName(self, language, script, territory, variant = ''):
"""Maps each code to the appropriate ID and name. """Maps each code to the appropriate ID and name.
Returns a 4-tuple of (ID, name) pairs corresponding to the Returns a 4-tuple of (ID, name) pairs corresponding to the
language, script, country and variant given. Raises a language, script, territory and variant given. Raises a
suitable error if any of them is unknown, indicating all that suitable error if any of them is unknown, indicating all that
are unknown plus suitable names for any that could sensibly be are unknown plus suitable names for any that could sensibly be
added to enumdata.py to make them known. added to enumdata.py to make them known.
@ -353,13 +353,13 @@ class CldrAccess (object):
try: try:
return (enum('language')[language], return (enum('language')[language],
enum('script')[script], enum('script')[script],
enum('country')[country], enum('territory')[territory],
enum('variant')[variant]) enum('variant')[variant])
except KeyError: except KeyError:
pass pass
parts, values = [], [language, script, country, variant] parts, values = [], [language, script, territory, variant]
for index, key in enumerate(('language', 'script', 'country', 'variant')): for index, key in enumerate(('language', 'script', 'territory', 'variant')):
naming, enums = self.__codeMap(key), enum(key) naming, enums = self.__codeMap(key), enum(key)
value = values[index] value = values[index]
if value not in enums: if value not in enums:
@ -372,7 +372,7 @@ class CldrAccess (object):
parts[-1] = 'and ' + parts[-1] parts[-1] = 'and ' + parts[-1]
assert parts assert parts
raise Error('Unknown ' + ', '.join(parts), raise Error('Unknown ' + ', '.join(parts),
language, script, country, variant) language, script, territory, variant)
@staticmethod @staticmethod
def __checkEnum(given, proper, scraps, def __checkEnum(given, proper, scraps,
@ -410,12 +410,12 @@ class CldrAccess (object):
for k in self.__parentLocale.keys(): for k in self.__parentLocale.keys():
for f in k.split('_'): for f in k.split('_'):
scraps.add(f) scraps.add(f)
from enumdata import language_map, country_map, script_map from enumdata import language_map, territory_map, script_map
language = dict((v, k) for k, v in language_map.values() if not v.isspace()) language = dict((v, k) for k, v in language_map.values() if not v.isspace())
country = dict((v, k) for k, v in country_map.values() if v != 'ZZ') territory = dict((v, k) for k, v in territory_map.values() if v != 'ZZ')
script = dict((v, k) for k, v in script_map.values() if v != 'Zzzz') script = dict((v, k) for k, v in script_map.values() if v != 'Zzzz')
lang = dict(self.__checkEnum(language, self.__codeMap('language'), scraps)) lang = dict(self.__checkEnum(language, self.__codeMap('language'), scraps))
land = dict(self.__checkEnum(country, self.__codeMap('country'), scraps)) land = dict(self.__checkEnum(territory, self.__codeMap('territory'), scraps))
text = dict(self.__checkEnum(script, self.__codeMap('script'), scraps)) text = dict(self.__checkEnum(script, self.__codeMap('script'), scraps))
if lang or land or text: if lang or land or text:
grumble("""\ grumble("""\
@ -427,7 +427,7 @@ enumdata.py (keeping the old name as an alias):
+ '\n\t'.join('{} -> {}'.format(k, v) for k, v in lang.items()) + '\n\t'.join('{} -> {}'.format(k, v) for k, v in lang.items())
+ '\n') + '\n')
if land: if land:
grumble('Country:\n\t' grumble('Territory:\n\t'
+ '\n\t'.join('{} -> {}'.format(k, v) for k, v in land.items()) + '\n\t'.join('{} -> {}'.format(k, v) for k, v in land.items())
+ '\n') + '\n')
if text: if text:
@ -460,7 +460,7 @@ enumdata.py (keeping the old name as an alias):
</supplementalData> </supplementalData>
""" """
zones = self.supplement('windowsZones.xml') zones = self.supplement('windowsZones.xml')
enum = self.__enumMap('country') enum = self.__enumMap('territory')
badZones, unLands, defaults, windows = set(), set(), {}, {} badZones, unLands, defaults, windows = set(), set(), {}, {}
for name, attrs in zones.find('windowsZones/mapTimezones'): for name, attrs in zones.find('windowsZones/mapTimezones'):
@ -469,7 +469,7 @@ enumdata.py (keeping the old name as an alias):
wid, code = attrs['other'], attrs['territory'] wid, code = attrs['other'], attrs['territory']
data = dict(windowsId = wid, data = dict(windowsId = wid,
countryCode = code, territoryCode = code,
ianaList = attrs['type']) ianaList = attrs['type'])
try: try:
@ -487,11 +487,11 @@ enumdata.py (keeping the old name as an alias):
except KeyError: except KeyError:
unLands.append(code) unLands.append(code)
continue continue
data.update(countryId = cid, country = name) data.update(territoryId = cid, territory = name)
windows[key, cid] = data windows[key, cid] = data
if unLands: if unLands:
raise Error('Unknown country codes, please add to enumdata.py: ' raise Error('Unknown territory codes, please add to enumdata.py: '
+ ', '.join(sorted(unLands))) + ', '.join(sorted(unLands)))
if badZones: if badZones:
@ -580,7 +580,7 @@ enumdata.py (keeping the old name as an alias):
for elt in source.findNodes('currencyData/region'): for elt in source.findNodes('currencyData/region'):
iso, digits, rounding = '', 2, 1 iso, digits, rounding = '', 2, 1
try: try:
country = elt.dom.attributes['iso3166'].nodeValue territory = elt.dom.attributes['iso3166'].nodeValue
except KeyError: except KeyError:
continue continue
for child in elt.findAllChildren('currency'): for child in elt.findAllChildren('currency'):
@ -599,7 +599,7 @@ enumdata.py (keeping the old name as an alias):
'currencyData/fractions/info[iso4217={}]'.format(iso)): 'currencyData/fractions/info[iso4217={}]'.format(iso)):
digits = data['digits'] digits = data['digits']
rounding = data['rounding'] rounding = data['rounding']
cache[country] = iso, digits, rounding cache[territory] = iso, digits, rounding
assert cache assert cache
return cache return cache
@ -673,10 +673,10 @@ enumdata.py (keeping the old name as an alias):
# They're not actually lists: mappings from numeric value # They're not actually lists: mappings from numeric value
# to pairs of full name and short code. What we want, in # to pairs of full name and short code. What we want, in
# each case, is a mapping from code to the other two. # each case, is a mapping from code to the other two.
from enumdata import language_map, script_map, country_map from enumdata import language_map, script_map, territory_map
for form, book, empty in (('language', language_map, 'AnyLanguage'), for form, book, empty in (('language', language_map, 'AnyLanguage'),
('script', script_map, 'AnyScript'), ('script', script_map, 'AnyScript'),
('country', country_map, 'AnyTerritory')): ('territory', territory_map, 'AnyTerritory')):
cache[form] = dict((pair[1], (num, pair[0])) cache[form] = dict((pair[1], (num, pair[0]))
for num, pair in book.items() if pair[0] != 'C') for num, pair in book.items() if pair[0] != 'C')
# (Have to filter out the C locale, as we give it the # (Have to filter out the C locale, as we give it the
@ -693,7 +693,7 @@ enumdata.py (keeping the old name as an alias):
def __codeMap(self, key, cache = {}, def __codeMap(self, key, cache = {},
# Maps our name for it to CLDR's name: # Maps our name for it to CLDR's name:
naming = {'language': 'languages', 'script': 'scripts', naming = {'language': 'languages', 'script': 'scripts',
'country': 'territories', 'variant': 'variants'}): 'territory': 'territories', 'variant': 'variants'}):
if not cache: if not cache:
root = self.xml('common', 'main', 'en.xml').root.findUniqueChild('localeDisplayNames') root = self.xml('common', 'main', 'en.xml').root.findUniqueChild('localeDisplayNames')
for dst, src in naming.items(): for dst, src in naming.items():

View File

@ -42,7 +42,7 @@ standard output. This file is the input needed by
When you update the CLDR data, be sure to also update When you update the CLDR data, be sure to also update
src/corelib/text/qt_attribution.json's entry for unicode-cldr. Check src/corelib/text/qt_attribution.json's entry for unicode-cldr. Check
this script's output for unknown language, country or script messages; this script's output for unknown language, territory or script messages;
if any can be resolved, use their entry in common/main/en.xml to if any can be resolved, use their entry in common/main/en.xml to
append new entries to enumdata.py's lists and update documentation in append new entries to enumdata.py's lists and update documentation in
src/corelib/text/qlocale.qdoc, adding the new entries in alphabetic src/corelib/text/qlocale.qdoc, adding the new entries in alphabetic

View File

@ -291,13 +291,13 @@ class ZoneIdWriter (SourceFileEditor):
windowsIdData, ianaIdData = ByteArrayData(), ByteArrayData() windowsIdData, ianaIdData = ByteArrayData(), ByteArrayData()
# Write Windows/IANA table # Write Windows/IANA table
out('// Windows ID Key, Country Enum, IANA ID Index\n') out('// Windows ID Key, Territory Enum, IANA ID Index\n')
out('static const QZoneData zoneDataTable[] = {\n') out('static const QZoneData zoneDataTable[] = {\n')
for index, data in sorted(windowsIds.items()): for index, data in sorted(windowsIds.items()):
out(' {{ {:6d},{:6d},{:6d} }}, // {} / {}\n'.format( out(' {{ {:6d},{:6d},{:6d} }}, // {} / {}\n'.format(
data['windowsKey'], data['countryId'], data['windowsKey'], data['territoryId'],
ianaIdData.append(data['ianaList']), ianaIdData.append(data['ianaList']),
data['windowsId'], data['country'])) data['windowsId'], data['territory']))
out(' { 0, 0, 0 } // Trailing zeroes\n') out(' { 0, 0, 0 } // Trailing zeroes\n')
out('};\n\n') out('};\n\n')

View File

@ -28,7 +28,7 @@
############################################################################# #############################################################################
# A run of cldr2qlocalexml.py will produce output reporting any # A run of cldr2qlocalexml.py will produce output reporting any
# language, script and country codes it sees, in data, for which it # language, script and territory codes it sees, in data, for which it
# can find a name (taken always from en.xml) that could potentially be # can find a name (taken always from en.xml) that could potentially be
# used. There is no point adding a mapping for such a code unless the # used. There is no point adding a mapping for such a code unless the
# CLDR's common/main/ contains an XML file for at least one locale # CLDR's common/main/ contains an XML file for at least one locale
@ -36,7 +36,7 @@
# Each *_list reflects the current values of its enums in qlocale.h; # Each *_list reflects the current values of its enums in qlocale.h;
# if new xml language files are available in CLDR, these languages and # if new xml language files are available in CLDR, these languages and
# countries need to be *appended* to this list (for compatibility # territories need to be *appended* to this list (for compatibility
# between versions). Include any spaces present in names (scripts # between versions). Include any spaces present in names (scripts
# shall squish them out for the enum entries) in *_list, but use the # shall squish them out for the enum entries) in *_list, but use the
# squished forms of names in the *_aliases mappings. # squished forms of names in the *_aliases mappings.
@ -408,7 +408,7 @@ language_aliases = {
'Kirghiz': 'Kyrgyz' 'Kirghiz': 'Kyrgyz'
} }
country_map = { territory_map = {
0: ("AnyTerritory", "ZZ"), 0: ("AnyTerritory", "ZZ"),
1: ("Afghanistan", "AF"), 1: ("Afghanistan", "AF"),
@ -677,7 +677,7 @@ country_map = {
261: ("Zimbabwe", "ZW"), 261: ("Zimbabwe", "ZW"),
} }
country_aliases = { territory_aliases = {
# Renamings prior to Qt 6.0 (CLDR v37): # Renamings prior to Qt 6.0 (CLDR v37):
'DemocraticRepublicOfCongo': 'CongoKinshasa', 'DemocraticRepublicOfCongo': 'CongoKinshasa',
'PeoplesRepublicOfCongo': 'CongoBrazzaville', 'PeoplesRepublicOfCongo': 'CongoBrazzaville',

View File

@ -227,7 +227,7 @@ class LocaleScanner (object):
def tagCodes(self): def tagCodes(self):
"""Yields four tag codes """Yields four tag codes
The tag codes are language, script, country and variant; an The tag codes are language, script, territory and variant; an
empty value for any of them indicates that no value was empty value for any of them indicates that no value was
provided. The values are obtained from the primary file's provided. The values are obtained from the primary file's
top-level <identity> element. An Error is raised if any top-level <identity> element. An Error is raised if any
@ -259,7 +259,7 @@ class LocaleScanner (object):
"""Fetches currency data for this locale. """Fetches currency data for this locale.
Single argument, isoCode, is the ISO currency code for the Single argument, isoCode, is the ISO currency code for the
currency in use in the country. See also numericData, which currency in use in the territory. See also numericData, which
includes some currency formats. includes some currency formats.
""" """
if isoCode: if isoCode:
@ -347,10 +347,10 @@ class LocaleScanner (object):
stem + '{}Formats/{}FormatLength[{}]/{}Format/pattern'.format( stem + '{}Formats/{}FormatLength[{}]/{}Format/pattern'.format(
key, key, pair[1], key)))) key, key, pair[1], key))))
def endonyms(self, language, script, country, variant): def endonyms(self, language, script, territory, variant):
# TODO: take variant into account ? # TODO: take variant into account ?
for seq in ((language, script, country), for seq in ((language, script, territory),
(language, script), (language, country), (language,)): (language, script), (language, territory), (language,)):
if not all(seq): if not all(seq):
continue continue
try: try:
@ -365,9 +365,9 @@ class LocaleScanner (object):
# grumble(failed to find endonym for language) # grumble(failed to find endonym for language)
yield 'languageEndonym', '' yield 'languageEndonym', ''
yield ('countryEndonym', yield ('territoryEndonym',
self.find('localeDisplayNames/territories/territory[{}]' self.find('localeDisplayNames/territories/territory[{}]'
.format(country), '')) .format(territory), ''))
def unitData(self): def unitData(self):
yield ('byte_unit', yield ('byte_unit',

View File

@ -121,18 +121,18 @@ class QLocaleXmlReader (object):
# Lists of (id, name, code) triples: # Lists of (id, name, code) triples:
languages = tuple(self.__loadMap('language')) languages = tuple(self.__loadMap('language'))
scripts = tuple(self.__loadMap('script')) scripts = tuple(self.__loadMap('script'))
countries = tuple(self.__loadMap('country')) territories = tuple(self.__loadMap('territory'))
self.__likely = tuple(self.__likelySubtagsMap()) self.__likely = tuple(self.__likelySubtagsMap())
# Mappings {ID: (name, code)} # Mappings {ID: (name, code)}
self.languages = dict((v[0], v[1:]) for v in languages) self.languages = dict((v[0], v[1:]) for v in languages)
self.scripts = dict((v[0], v[1:]) for v in scripts) self.scripts = dict((v[0], v[1:]) for v in scripts)
self.countries = dict((v[0], v[1:]) for v in countries) self.territories = dict((v[0], v[1:]) for v in territories)
# Private mappings {name: (ID, code)} # Private mappings {name: (ID, code)}
self.__langByName = dict((v[1], (v[0], v[2])) for v in languages) self.__langByName = dict((v[1], (v[0], v[2])) for v in languages)
self.__textByName = dict((v[1], (v[0], v[2])) for v in scripts) self.__textByName = dict((v[1], (v[0], v[2])) for v in scripts)
self.__landByName = dict((v[1], (v[0], v[2])) for v in countries) self.__landByName = dict((v[1], (v[0], v[2])) for v in territories)
# Other properties: # Other properties:
self.dupes = set(v[1] for v in languages) & set(v[1] for v in countries) self.dupes = set(v[1] for v in languages) & set(v[1] for v in territories)
self.cldrVersion = self.__firstChildText(self.root, "version") self.cldrVersion = self.__firstChildText(self.root, "version")
def loadLocaleMap(self, calendars, grumble = lambda text: None): def loadLocaleMap(self, calendars, grumble = lambda text: None):
@ -142,18 +142,18 @@ class QLocaleXmlReader (object):
locale = Locale.fromXmlData(lambda k: kid(elt, k), calendars) locale = Locale.fromXmlData(lambda k: kid(elt, k), calendars)
language = self.__langByName[locale.language][0] language = self.__langByName[locale.language][0]
script = self.__textByName[locale.script][0] script = self.__textByName[locale.script][0]
country = self.__landByName[locale.country][0] territory = self.__landByName[locale.territory][0]
if language != 1: # C if language != 1: # C
if country == 0: if territory == 0:
grumble('loadLocaleMap: No country id for "{}"\n'.format(locale.language)) grumble('loadLocaleMap: No territory id for "{}"\n'.format(locale.language))
if script == 0: if script == 0:
# Find default script for the given language and country - see: # Find default script for the given language and territory - see:
# http://www.unicode.org/reports/tr35/#Likely_Subtags # http://www.unicode.org/reports/tr35/#Likely_Subtags
try: try:
try: try:
to = likely[(locale.language, 'AnyScript', locale.country)] to = likely[(locale.language, 'AnyScript', locale.territory)]
except KeyError: except KeyError:
to = likely[(locale.language, 'AnyScript', 'AnyTerritory')] to = likely[(locale.language, 'AnyScript', 'AnyTerritory')]
except KeyError: except KeyError:
@ -162,7 +162,7 @@ class QLocaleXmlReader (object):
locale.script = to[1] locale.script = to[1]
script = self.__textByName[locale.script][0] script = self.__textByName[locale.script][0]
yield (language, script, country), locale yield (language, script, territory), locale
def languageIndices(self, locales): def languageIndices(self, locales):
index = 0 index = 0
@ -190,11 +190,11 @@ class QLocaleXmlReader (object):
'_'.join(tag(give)), ids(give)) '_'.join(tag(give)), ids(give))
def defaultMap(self): def defaultMap(self):
"""Map language and script to their default country by ID. """Map language and script to their default territory by ID.
Yields ((language, script), country) wherever the likely Yields ((language, script), territory) wherever the likely
sub-tags mapping says language's default locale uses the given sub-tags mapping says language's default locale uses the given
script and country.""" script and territory."""
for have, give in self.__likely: for have, give in self.__likely:
if have[1:] == ('AnyScript', 'AnyTerritory') and give[2] != 'AnyTerritory': if have[1:] == ('AnyScript', 'AnyTerritory') and give[2] != 'AnyTerritory':
assert have[0] == give[0], (have, give) assert have[0] == give[0], (have, give)
@ -209,7 +209,7 @@ class QLocaleXmlReader (object):
yield int(kid(element, 'id')), kid(element, 'name'), kid(element, 'code') yield int(kid(element, 'id')), kid(element, 'name'), kid(element, 'code')
def __likelySubtagsMap(self): def __likelySubtagsMap(self):
def triplet(element, keys=('language', 'script', 'country'), kid = self.__firstChildText): def triplet(element, keys=('language', 'script', 'territory'), kid = self.__firstChildText):
return tuple(kid(element, key) for key in keys) return tuple(kid(element, key) for key in keys)
kid = self.__firstChildElt kid = self.__firstChildElt
@ -334,10 +334,10 @@ class QLocaleXmlWriter (object):
# Output of various sections, in their usual order: # Output of various sections, in their usual order:
def enumData(self): def enumData(self):
from enumdata import language_map, script_map, country_map from enumdata import language_map, script_map, territory_map
self.__enumTable('language', language_map) self.__enumTable('language', language_map)
self.__enumTable('script', script_map) self.__enumTable('script', script_map)
self.__enumTable('country', country_map) self.__enumTable('territory', territory_map)
def likelySubTags(self, entries): def likelySubTags(self, entries):
self.__openTag('likelySubtags') self.__openTag('likelySubtags')
@ -394,7 +394,7 @@ class QLocaleXmlWriter (object):
self.__openTag(tag) self.__openTag(tag)
self.inTag('language', likely[0]) self.inTag('language', likely[0])
self.inTag('script', likely[1]) self.inTag('script', likely[1])
self.inTag('country', likely[2]) self.inTag('territory', likely[2])
# self.inTag('variant', likely[3]) # self.inTag('variant', likely[3])
self.__closeTag(tag) self.__closeTag(tag)
@ -436,7 +436,7 @@ class Locale (object):
# Convert from CLDR format-strings to QDateTimeParser ones: # Convert from CLDR format-strings to QDateTimeParser ones:
__asfmt = ("longDateFormat", "shortDateFormat", "longTimeFormat", "shortTimeFormat") __asfmt = ("longDateFormat", "shortDateFormat", "longTimeFormat", "shortTimeFormat")
# Just use the raw text: # Just use the raw text:
__astxt = ("language", "languageEndonym", "script", "country", "countryEndonym", __astxt = ("language", "languageEndonym", "script", "territory", "territoryEndonym",
"decimal", "group", "zero", "decimal", "group", "zero",
"list", "percent", "minus", "plus", "exp", "list", "percent", "minus", "plus", "exp",
"quotationStart", "quotationEnd", "quotationStart", "quotationEnd",
@ -494,7 +494,7 @@ class Locale (object):
form used by CLDR; its default is ('gregorian',). form used by CLDR; its default is ('gregorian',).
""" """
get = lambda k: getattr(self, k) get = lambda k: getattr(self, k)
for key in ('language', 'script', 'country'): for key in ('language', 'script', 'territory'):
write(key, get(key)) write(key, get(key))
write('{}code'.format(key), get('{}_code'.format(key))) write('{}code'.format(key), get('{}_code'.format(key)))
@ -502,7 +502,7 @@ class Locale (object):
'percent', 'minus', 'plus', 'exp'): 'percent', 'minus', 'plus', 'exp'):
write(key, get(key)) write(key, get(key))
for key in ('languageEndonym', 'countryEndonym', for key in ('languageEndonym', 'territoryEndonym',
'quotationStart', 'quotationEnd', 'quotationStart', 'quotationEnd',
'alternateQuotationStart', 'alternateQuotationEnd', 'alternateQuotationStart', 'alternateQuotationEnd',
'listPatternPartStart', 'listPatternPartMiddle', 'listPatternPartStart', 'listPatternPartMiddle',
@ -591,7 +591,7 @@ class Locale (object):
return cls(cls.__monthNames(calendars), return cls(cls.__monthNames(calendars),
language='C', language_code='0', languageEndonym='', language='C', language_code='0', languageEndonym='',
script='AnyScript', script_code='0', script='AnyScript', script_code='0',
country='AnyTerritory', country_code='0', countryEndonym='', territory='AnyTerritory', territory_code='0', territoryEndonym='',
groupSizes=(3, 3, 1), groupSizes=(3, 3, 1),
decimal='.', group=',', list=';', percent='%', decimal='.', group=',', list=';', percent='%',
zero='0', minus='-', plus='+', exp='e', zero='0', minus='-', plus='+', exp='e',

View File

@ -47,28 +47,28 @@ def compareLocaleKeys(key1, key2):
return key1[0] - key2[0] return key1[0] - key2[0]
defaults = compareLocaleKeys.default_map defaults = compareLocaleKeys.default_map
# maps {(language, script): country} by ID # maps {(language, script): territory} by ID
try: try:
country = defaults[key1[:2]] territory = defaults[key1[:2]]
except KeyError: except KeyError:
pass pass
else: else:
if key1[2] == country: if key1[2] == territory:
return -1 return -1
if key2[2] == country: if key2[2] == territory:
return 1 return 1
if key1[1] == key2[1]: if key1[1] == key2[1]:
return key1[2] - key2[2] return key1[2] - key2[2]
try: try:
country = defaults[key2[:2]] territory = defaults[key2[:2]]
except KeyError: except KeyError:
pass pass
else: else:
if key2[2] == country: if key2[2] == territory:
return 1 return 1
if key1[2] == country: if key1[2] == territory:
return -1 return -1
return key1[1] - key2[1] return key1[1] - key2[1]
@ -327,7 +327,7 @@ class LocaleDataWriter (LocaleSourceEditor):
currency_format_data.append(locale.currencyFormat), currency_format_data.append(locale.currencyFormat),
currency_format_data.append(locale.currencyNegativeFormat), currency_format_data.append(locale.currencyNegativeFormat),
endonyms_data.append(locale.languageEndonym), endonyms_data.append(locale.languageEndonym),
endonyms_data.append(locale.countryEndonym)) # 6 entries endonyms_data.append(locale.territoryEndonym)) # 6 entries
) # Total: 37 entries ) # Total: 37 entries
assert len(ranges) == 37 assert len(ranges) == 37
@ -341,7 +341,7 @@ class LocaleDataWriter (LocaleSourceEditor):
locale.firstDayOfWeek, locale.weekendStart, locale.weekendEnd, locale.firstDayOfWeek, locale.weekendStart, locale.weekendEnd,
locale.groupTop, locale.groupHigher, locale.groupLeast) )) locale.groupTop, locale.groupHigher, locale.groupLeast) ))
+ ', // {}/{}/{}\n'.format( + ', // {}/{}/{}\n'.format(
locale.language, locale.script, locale.country)) locale.language, locale.script, locale.territory))
self.writer.write(formatLine(*( # All zeros, matching the format: self.writer.write(formatLine(*( # All zeros, matching the format:
(0,) * 3 + (0,) * 37 * 2 (0,) * 3 + (0,) * 37 * 2
+ (currencyIsoCodeData(0),) + (currencyIsoCodeData(0),)
@ -393,8 +393,8 @@ class LocaleDataWriter (LocaleSourceEditor):
def scriptNames(self, scripts): def scriptNames(self, scripts):
self.__writeNameData(self.writer.write, scripts, 'script') self.__writeNameData(self.writer.write, scripts, 'script')
def countryNames(self, countries): def territoryNames(self, territories):
self.__writeNameData(self.writer.write, countries, 'territory') self.__writeNameData(self.writer.write, territories, 'territory')
# TODO: unify these next three into the previous three; kept # TODO: unify these next three into the previous three; kept
# separate for now to verify we're not changing data. # separate for now to verify we're not changing data.
@ -405,8 +405,8 @@ class LocaleDataWriter (LocaleSourceEditor):
def scriptCodes(self, scripts): def scriptCodes(self, scripts):
self.__writeCodeList(self.writer.write, scripts, 'script', 4) self.__writeCodeList(self.writer.write, scripts, 'script', 4)
def countryCodes(self, countries): # TODO: unify with countryNames() def territoryCodes(self, territories): # TODO: unify with territoryNames()
self.__writeCodeList(self.writer.write, countries, 'territory', 3) self.__writeCodeList(self.writer.write, territories, 'territory', 3)
class CalendarDataWriter (LocaleSourceEditor): class CalendarDataWriter (LocaleSourceEditor):
formatCalendar = ( formatCalendar = (
@ -444,7 +444,7 @@ class CalendarDataWriter (LocaleSourceEditor):
(locale.standaloneShortMonths, locale.shortMonths, (locale.standaloneShortMonths, locale.shortMonths,
locale.standaloneNarrowMonths, locale.narrowMonths))) locale.standaloneNarrowMonths, locale.narrowMonths)))
except ValueError as e: except ValueError as e:
e.args += (locale.language, locale.script, locale.country, stem) e.args += (locale.language, locale.script, locale.territory, stem)
raise raise
self.writer.write( self.writer.write(
@ -452,7 +452,7 @@ class CalendarDataWriter (LocaleSourceEditor):
key + key +
tuple(r.index for r in ranges) + tuple(r.index for r in ranges) +
tuple(r.length for r in ranges) )) tuple(r.length for r in ranges) ))
+ '// {}/{}/{}\n'.format(locale.language, locale.script, locale.country)) + '// {}/{}/{}\n'.format(locale.language, locale.script, locale.territory))
self.writer.write(self.formatCalendar(*( (0,) * (3 + 6 * 2) )) self.writer.write(self.formatCalendar(*( (0,) * (3 + 6 * 2) ))
+ '// trailing zeros\n') + '// trailing zeros\n')
self.writer.write('};\n') self.writer.write('};\n')
@ -468,9 +468,9 @@ class LocaleHeaderWriter (SourceFileEditor):
self.__enum('Language', languages, self.__language) self.__enum('Language', languages, self.__language)
self.writer.write('\n') self.writer.write('\n')
def countries(self, countries): def territories(self, territories):
self.writer.write(" // ### Qt 7: Rename to Territory\n") self.writer.write(" // ### Qt 7: Rename to Territory\n")
self.__enum('Country', countries, self.__country, 'Territory') self.__enum('Country', territories, self.__territory, 'Territory')
def scripts(self, scripts): def scripts(self, scripts):
self.__enum('Script', scripts, self.__script) self.__enum('Script', scripts, self.__script)
@ -478,7 +478,7 @@ class LocaleHeaderWriter (SourceFileEditor):
# Implementation details # Implementation details
from enumdata import (language_aliases as __language, from enumdata import (language_aliases as __language,
country_aliases as __country, territory_aliases as __territory,
script_aliases as __script) script_aliases as __script)
def __enum(self, name, book, alias, suffix = None): def __enum(self, name, book, alias, suffix = None):
@ -562,11 +562,11 @@ def main(args, out, err):
writer.writer.write('\n') writer.writer.write('\n')
writer.languageNames(reader.languages) writer.languageNames(reader.languages)
writer.scriptNames(reader.scripts) writer.scriptNames(reader.scripts)
writer.countryNames(reader.countries) writer.territoryNames(reader.territories)
# TODO: merge the next three into the previous three # TODO: merge the next three into the previous three
writer.languageCodes(reader.languages) writer.languageCodes(reader.languages)
writer.scriptCodes(reader.scripts) writer.scriptCodes(reader.scripts)
writer.countryCodes(reader.countries) writer.territoryCodes(reader.territories)
except Error as e: except Error as e:
writer.cleanup() writer.cleanup()
err.write('\nError updating locale data: ' + e.message + '\n') err.write('\nError updating locale data: ' + e.message + '\n')
@ -605,7 +605,7 @@ def main(args, out, err):
try: try:
writer.languages(reader.languages) writer.languages(reader.languages)
writer.scripts(reader.scripts) writer.scripts(reader.scripts)
writer.countries(reader.countries) writer.territories(reader.territories)
except Error as e: except Error as e:
writer.cleanup() writer.cleanup()
err.write('\nError updating qlocale.h: ' + e.message + '\n') err.write('\nError updating qlocale.h: ' + e.message + '\n')