2019-08-04 15:56:53 +00:00
|
|
|
|
#!/usr/bin/python3
|
2019-08-02 14:07:55 +00:00
|
|
|
|
#-*- coding: UTF-8 -*-
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-08 19:53:30 +00:00
|
|
|
|
# Data is from https://unicode.org/Public/cldr/35.1/core.zip
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-10 19:15:18 +00:00
|
|
|
|
import os, sys, glob, re
|
2019-08-01 18:08:02 +00:00
|
|
|
|
import xml.etree.ElementTree as ET
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-07 13:53:57 +00:00
|
|
|
|
printenumsandexit = ('--printenums' in sys.argv)
|
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
def mapcopy(frommap, tomap):
|
|
|
|
|
for key in frommap.keys():
|
|
|
|
|
tomap[key] = frommap[key]
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-05 22:24:47 +00:00
|
|
|
|
def mapmerge(frommap, tomap, defaultmap):
|
|
|
|
|
for key in frommap.keys():
|
|
|
|
|
if frommap[key] == defaultmap[key]:
|
|
|
|
|
continue
|
|
|
|
|
tomap[key] = frommap[key]
|
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
def listcopy(fromlist, tolist):
|
|
|
|
|
for entry in fromlist:
|
|
|
|
|
tolist.append(entry)
|
|
|
|
|
|
|
|
|
|
def stripxmltext(fromxmltext):
|
|
|
|
|
result = fromxmltext.replace('\n', '')
|
2019-08-02 14:07:55 +00:00
|
|
|
|
result = result.replace('\t', '')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# 3-passes of double-space removal seems to be enough for all cases
|
2019-08-11 22:08:29 +00:00
|
|
|
|
for r in range(3):
|
2019-08-04 15:56:53 +00:00
|
|
|
|
result = result.replace(' ', ' ')
|
2019-08-02 14:07:55 +00:00
|
|
|
|
return result.strip()
|
|
|
|
|
|
2019-08-11 12:03:33 +00:00
|
|
|
|
def normalizestring(fromstring):
|
|
|
|
|
result = fromstring.replace(' ', '')
|
|
|
|
|
result = result.replace('-', '')
|
|
|
|
|
result = result.replace("'", '')
|
|
|
|
|
result = result.replace('&', 'And')
|
|
|
|
|
result = result.replace('(', '')
|
|
|
|
|
result = result.replace(')', '')
|
|
|
|
|
result = result.replace('St.', 'St')
|
|
|
|
|
result = result.replace('U.S.', 'UnitedStates')
|
|
|
|
|
# UTF-8 chars
|
|
|
|
|
result = result.replace(u'ʼ', '')
|
|
|
|
|
result = result.replace(u'’', '')
|
|
|
|
|
result = result.replace(u'ü', 'u')
|
|
|
|
|
result = result.replace(u'å', 'a')
|
|
|
|
|
result = result.replace(u'ç', 'c')
|
|
|
|
|
result = result.replace(u'õ', 'o')
|
|
|
|
|
result = result.replace(u'Å', 'A')
|
|
|
|
|
result = result.replace(u'ô', 'o')
|
|
|
|
|
result = result.replace(u'ã', 'a')
|
|
|
|
|
result = result.replace(u'é', 'e')
|
|
|
|
|
result = result.replace(u'í', 'i')
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def xmlmerge(fromxml, fromxml2):
|
|
|
|
|
tree = ET.parse(fromxml)
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
tree2 = ET.parse(fromxml2)
|
|
|
|
|
root2 = tree2.getroot()
|
|
|
|
|
for element in root:
|
|
|
|
|
root2.insert(0, element)
|
|
|
|
|
return root2
|
|
|
|
|
|
2019-08-04 20:31:26 +00:00
|
|
|
|
def touint(fromstring):
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# NOTE: symbols (plus, minus, etc.) are assumed to be single character which is not true for
|
|
|
|
|
# many of the locales, however the API for those does not handle them as strings thus the first
|
|
|
|
|
# character only is used
|
|
|
|
|
return ord(fromstring)
|
|
|
|
|
|
2019-08-04 18:23:29 +00:00
|
|
|
|
def tochar(fromstring):
|
|
|
|
|
if fromstring:
|
|
|
|
|
return '"%s\\0"' % fromstring
|
2019-08-04 15:56:53 +00:00
|
|
|
|
return 'Q_NULLPTR'
|
|
|
|
|
|
2019-08-06 15:33:59 +00:00
|
|
|
|
def tochararray(fromstringlist):
|
|
|
|
|
result = '{ '
|
|
|
|
|
for string in fromstringlist:
|
|
|
|
|
result = '%s%s, ' % (result, tochar(string))
|
|
|
|
|
result = '%s }' % result
|
|
|
|
|
result = result.replace(', }', ' }')
|
|
|
|
|
return result
|
|
|
|
|
|
2019-08-04 18:23:29 +00:00
|
|
|
|
def todayenum(day):
|
2019-08-04 15:56:53 +00:00
|
|
|
|
if day == 'mon':
|
|
|
|
|
return 'Qt::Monday'
|
|
|
|
|
elif day == 'tue':
|
|
|
|
|
return 'Qt::Tuesday'
|
|
|
|
|
elif day == 'wed':
|
|
|
|
|
return 'Qt::Wednesday'
|
|
|
|
|
elif day == 'thu':
|
|
|
|
|
return 'Qt::Thursday'
|
|
|
|
|
elif day == 'fri':
|
|
|
|
|
return 'Qt::Friday'
|
|
|
|
|
elif day == 'sat':
|
|
|
|
|
return 'Qt::Saturday'
|
|
|
|
|
elif day == 'sun':
|
|
|
|
|
return 'Qt::Sunday'
|
|
|
|
|
print('Unknown day: %s' % day)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
def tolistformat(fromformat):
|
|
|
|
|
result = fromformat.replace('{0}', '%1')
|
|
|
|
|
result = result.replace('{1}', '%2')
|
|
|
|
|
result = result.replace('{2}', '%3')
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def tocurrencyformat(fromformat, frommap):
|
|
|
|
|
result = []
|
|
|
|
|
# currency format can optionally have negative form separated by ';'
|
|
|
|
|
for fmt in fromformat.split(';'):
|
|
|
|
|
fmt = fmt.replace('0', '#')
|
|
|
|
|
fmt = fmt.replace(',', '#')
|
|
|
|
|
fmt = fmt.replace('.', '#')
|
2019-08-11 10:03:56 +00:00
|
|
|
|
for r in range(10):
|
2019-08-04 15:56:53 +00:00
|
|
|
|
fmt = fmt.replace('##', "#")
|
|
|
|
|
fmt = fmt.replace('#', "%1")
|
|
|
|
|
fmt = fmt.replace(u'\xa4', "%2")
|
|
|
|
|
fmt = fmt.replace('-', frommap['minus'])
|
|
|
|
|
fmt = fmt.replace('+', frommap['plus'])
|
|
|
|
|
result.append(fmt)
|
|
|
|
|
return result
|
|
|
|
|
|
2019-08-05 01:32:21 +00:00
|
|
|
|
def todatetimeformat(fromformat):
|
2019-08-07 20:32:13 +00:00
|
|
|
|
# valid are y, m, M, d, h, H, s, a, A, z and t
|
2019-08-05 01:32:21 +00:00
|
|
|
|
unsupportedtags = [
|
|
|
|
|
'g',
|
|
|
|
|
'u',
|
|
|
|
|
'q',
|
|
|
|
|
'l',
|
|
|
|
|
'w',
|
|
|
|
|
'f',
|
|
|
|
|
'j',
|
|
|
|
|
]
|
2019-08-12 00:50:49 +00:00
|
|
|
|
replacementtags = {
|
2019-08-12 12:11:23 +00:00
|
|
|
|
'MMMMM' : 'MMM', # narrow month name
|
|
|
|
|
'LLLLL' : 'MMM', # stand-alone narrow month name
|
|
|
|
|
'E' : 'ddd', 'EE' : 'ddd', 'EEE' : 'ddd', 'EEEEE' : 'ddd', 'EEEE' : 'dddd', # day of week
|
|
|
|
|
'e' : 'ddd', 'ee' : 'ddd', 'eee' : 'ddd', 'eeeee' : 'ddd', 'eeee' : 'dddd', # local day of week
|
|
|
|
|
'c' : 'ddd', 'cc' : 'ddd', 'ccc' : 'ddd', 'ccccc' : 'ddd', 'cccc' : 'dddd', # stand-alone local day of week
|
|
|
|
|
'K' : 'h', # Hour 0-11
|
|
|
|
|
'k' : 'H', # Hour 1-24
|
|
|
|
|
'z' : 't', 'zz' : 't', 'zzz' : 't', 'zzzz' : 't', # timezone
|
|
|
|
|
'Z' : 't', 'ZZ' : 't', 'ZZZ' : 't', 'ZZZZ' : 't', # timezone
|
|
|
|
|
'v' : 't', 'vv' : 't', 'vvv' : 't', 'vvvv' : 't', # timezone
|
|
|
|
|
'V' : 't', 'VV' : 't', 'VVV' : 't', 'VVVV' : 't', # timezone
|
|
|
|
|
'L' : 'M', # stand-alone month names. not supported
|
2019-08-12 00:50:49 +00:00
|
|
|
|
}
|
|
|
|
|
replacementregex = {
|
2019-08-12 12:11:23 +00:00
|
|
|
|
r'y' : 'yyyy', # four-digit year without leading zeroes
|
|
|
|
|
r'yyy{3,}' : 'yyyy', # more that three digits hence convert to four-digit year
|
|
|
|
|
r'S{1,}' : '', # fractional seconds. not supported.
|
|
|
|
|
r'A{1,}' : '', # milliseconds in day. not supported.
|
|
|
|
|
r'a' : 'AP', # AM/PM
|
2019-08-12 00:50:49 +00:00
|
|
|
|
}
|
2019-08-05 10:57:58 +00:00
|
|
|
|
possibleoccurences = [
|
2019-08-05 01:32:21 +00:00
|
|
|
|
'%s, ',
|
2019-08-06 18:56:47 +00:00
|
|
|
|
', %s',
|
2019-08-05 01:32:21 +00:00
|
|
|
|
'%s.',
|
2019-08-06 18:56:47 +00:00
|
|
|
|
'.%s',
|
2019-08-05 01:32:21 +00:00
|
|
|
|
'%s-',
|
2019-08-06 18:56:47 +00:00
|
|
|
|
'-%s',
|
|
|
|
|
'(%s)',
|
2019-08-12 00:50:49 +00:00
|
|
|
|
"('%s')",
|
|
|
|
|
'%s ',
|
|
|
|
|
' %s',
|
2019-08-05 01:32:21 +00:00
|
|
|
|
'%s',
|
|
|
|
|
]
|
|
|
|
|
result = fromformat
|
|
|
|
|
for tag in unsupportedtags:
|
|
|
|
|
uppertag = tag.upper()
|
2019-08-05 10:57:58 +00:00
|
|
|
|
for occurence in possibleoccurences:
|
|
|
|
|
result = result.replace(occurence % (tag * 4), '')
|
|
|
|
|
result = result.replace(occurence % (tag * 3), '')
|
|
|
|
|
result = result.replace(occurence % (tag * 2), '')
|
|
|
|
|
result = result.replace(occurence % tag, '')
|
|
|
|
|
result = result.replace(occurence % (uppertag * 4), '')
|
|
|
|
|
result = result.replace(occurence % (uppertag * 3), '')
|
|
|
|
|
result = result.replace(occurence % (uppertag * 2), '')
|
|
|
|
|
result = result.replace(occurence % uppertag, '')
|
2019-08-12 12:11:23 +00:00
|
|
|
|
for key in replacementregex.keys():
|
|
|
|
|
result = re.sub(key, replacementregex[key], result)
|
2019-08-12 00:50:49 +00:00
|
|
|
|
for key in replacementtags.keys():
|
|
|
|
|
result = result.replace(key, replacementtags[key])
|
2019-08-05 01:32:21 +00:00
|
|
|
|
return result
|
|
|
|
|
|
2019-08-04 20:31:26 +00:00
|
|
|
|
def tomonthslist(fromxmlelements, initialvalues):
|
2019-08-04 15:56:53 +00:00
|
|
|
|
result = []
|
|
|
|
|
listcopy(initialvalues, result)
|
|
|
|
|
for month in fromxmlelements:
|
|
|
|
|
monthtype = month.get('type')
|
|
|
|
|
if monthtype == '1':
|
|
|
|
|
result[0] = month.text
|
|
|
|
|
elif monthtype == '2':
|
|
|
|
|
result[1] = month.text
|
|
|
|
|
elif monthtype == '3':
|
|
|
|
|
result[2] = month.text
|
|
|
|
|
elif monthtype == '4':
|
|
|
|
|
result[3] = month.text
|
|
|
|
|
elif monthtype == '5':
|
|
|
|
|
result[4] = month.text
|
|
|
|
|
elif monthtype == '6':
|
|
|
|
|
result[5] = month.text
|
|
|
|
|
elif monthtype == '7':
|
|
|
|
|
result[6] = month.text
|
|
|
|
|
elif monthtype == '8':
|
|
|
|
|
result[7] = month.text
|
|
|
|
|
elif monthtype == '9':
|
|
|
|
|
result[8] = month.text
|
|
|
|
|
elif monthtype == '10':
|
|
|
|
|
result[9] = month.text
|
|
|
|
|
elif monthtype == '11':
|
|
|
|
|
result[10] = month.text
|
|
|
|
|
elif monthtype == '12':
|
|
|
|
|
result[11] = month.text
|
2019-08-05 20:27:33 +00:00
|
|
|
|
else:
|
|
|
|
|
print('Unknown month: %s' % monthtype)
|
|
|
|
|
sys.exit(1)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def todayslist(fromxmlelements, initialvalues):
|
|
|
|
|
result = []
|
|
|
|
|
listcopy(initialvalues, result)
|
|
|
|
|
for day in fromxmlelements:
|
|
|
|
|
daytype = day.get('type')
|
2019-08-12 11:46:53 +00:00
|
|
|
|
if daytype == 'mon':
|
2019-08-04 15:56:53 +00:00
|
|
|
|
result[0] = day.text
|
|
|
|
|
elif daytype == 'tue':
|
2019-08-12 11:46:53 +00:00
|
|
|
|
result[1] = day.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daytype == 'wed':
|
2019-08-12 11:46:53 +00:00
|
|
|
|
result[2] = day.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daytype == 'thu':
|
2019-08-12 11:46:53 +00:00
|
|
|
|
result[3] = day.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daytype == 'fri':
|
2019-08-12 11:46:53 +00:00
|
|
|
|
result[4] = day.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daytype == 'sat':
|
2019-08-12 11:46:53 +00:00
|
|
|
|
result[5] = day.text
|
|
|
|
|
elif daytype == 'sun':
|
2019-08-04 15:56:53 +00:00
|
|
|
|
result[6] = day.text
|
2019-08-05 20:27:33 +00:00
|
|
|
|
else:
|
|
|
|
|
print('Unknown day: %s' % daytype)
|
|
|
|
|
sys.exit(1)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
return result
|
|
|
|
|
|
2019-08-10 19:15:18 +00:00
|
|
|
|
def tolanguageenum(fromstring):
|
|
|
|
|
for key in languagemap.keys():
|
|
|
|
|
if fromstring == languagemap[key]['code']:
|
|
|
|
|
return 'QLocale::Language::%s' % key
|
|
|
|
|
# print('Unknown language: %s' % fromstring)
|
|
|
|
|
# sys.exit(1)
|
|
|
|
|
|
|
|
|
|
def toscriptenum(fromstring):
|
|
|
|
|
for key in scriptmap.keys():
|
|
|
|
|
if fromstring == scriptmap[key]['code']:
|
|
|
|
|
return 'QLocale::Script::%s' % key
|
|
|
|
|
# print('Unknown script: %s' % fromstring)
|
|
|
|
|
# sys.exit(1)
|
|
|
|
|
|
|
|
|
|
def tocountryenum(fromstring):
|
|
|
|
|
for key in countrymap.keys():
|
|
|
|
|
if fromstring == countrymap[key]['code']:
|
|
|
|
|
return 'QLocale::Country::%s' % key
|
|
|
|
|
# print('Unknown country: %s' % fromstring)
|
|
|
|
|
# sys.exit(1)
|
|
|
|
|
|
2019-08-07 14:48:16 +00:00
|
|
|
|
# printenum prints mapped values that have unique code only, the rest are set to the enum of the
|
|
|
|
|
# first occurence. the reason for doing so is because table lookups for figuring out language,
|
2019-08-08 19:53:30 +00:00
|
|
|
|
# script and country required for constructing QLocale from string (named locales) relies on the
|
|
|
|
|
# fact that there is only one code for each, if that is not the case constructing copy of locale
|
|
|
|
|
# from its name will not copy it correctly. printtable skips duplicate code entries entirely
|
2019-08-02 14:07:55 +00:00
|
|
|
|
def printenum(frommap, prefix):
|
|
|
|
|
keyscount = 0
|
2019-08-09 12:46:07 +00:00
|
|
|
|
aliascodes = []
|
|
|
|
|
seencodes = []
|
2019-08-02 14:07:55 +00:00
|
|
|
|
|
2019-08-07 14:48:16 +00:00
|
|
|
|
print(' enum %s {' % prefix)
|
2019-08-02 14:07:55 +00:00
|
|
|
|
# print Default and C first
|
2019-08-05 11:26:06 +00:00
|
|
|
|
for key in frommap.keys():
|
2019-08-02 14:07:55 +00:00
|
|
|
|
if not key in ('Any%s' % prefix, 'C'):
|
|
|
|
|
continue
|
|
|
|
|
print(' %s = %d,' % (key, keyscount))
|
|
|
|
|
keyscount += 1
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# now everything except those, save last key for later
|
2019-08-02 14:07:55 +00:00
|
|
|
|
lastkey = ''
|
|
|
|
|
for key in sorted(frommap.keys()):
|
|
|
|
|
if key in ('Any%s' % prefix, 'C'):
|
|
|
|
|
continue
|
2019-08-09 12:46:07 +00:00
|
|
|
|
code = frommap[key]['code']
|
|
|
|
|
if code in seencodes:
|
|
|
|
|
aliascodes.append(key)
|
2019-08-07 14:48:16 +00:00
|
|
|
|
continue
|
2019-08-09 12:46:07 +00:00
|
|
|
|
seencodes.append(code)
|
2019-08-02 14:07:55 +00:00
|
|
|
|
print(' %s = %d,' % (key, keyscount))
|
|
|
|
|
lastkey = key
|
|
|
|
|
keyscount += 1
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-07 14:48:16 +00:00
|
|
|
|
# now aliases
|
|
|
|
|
print('')
|
2019-08-09 12:46:07 +00:00
|
|
|
|
for alias in sorted(aliascodes):
|
|
|
|
|
aliascode = frommap[alias]['code']
|
2019-08-07 14:48:16 +00:00
|
|
|
|
aliasenum = None
|
|
|
|
|
for key in sorted(frommap.keys()):
|
2019-08-09 12:46:07 +00:00
|
|
|
|
code = frommap[key]['code']
|
|
|
|
|
if aliascode == code:
|
2019-08-07 14:48:16 +00:00
|
|
|
|
aliasenum == key
|
|
|
|
|
break
|
|
|
|
|
print(' %s = %s,' % (alias, key))
|
|
|
|
|
|
2019-08-02 14:07:55 +00:00
|
|
|
|
# print last key
|
|
|
|
|
print('\n Last%s = %s' % (prefix, lastkey))
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-07 14:48:16 +00:00
|
|
|
|
print(' };\n')
|
|
|
|
|
|
2019-08-02 14:07:55 +00:00
|
|
|
|
def printtable(frommap, prefix):
|
|
|
|
|
lowerprefix = prefix.lower()
|
2019-08-09 12:46:07 +00:00
|
|
|
|
seencodes = []
|
2019-08-07 14:48:16 +00:00
|
|
|
|
|
2019-08-02 14:07:55 +00:00
|
|
|
|
print('''static const struct %sTblData {
|
2019-08-10 11:37:22 +00:00
|
|
|
|
const QLocale::%s %s;
|
2019-08-01 18:08:02 +00:00
|
|
|
|
const char* name;
|
|
|
|
|
const char* code;
|
2019-08-02 14:07:55 +00:00
|
|
|
|
} %sTbl[] = {''' % (lowerprefix, prefix, lowerprefix, lowerprefix))
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-02 14:07:55 +00:00
|
|
|
|
# print Default and C first
|
|
|
|
|
for key in frommap.keys():
|
|
|
|
|
if not key in ('Any%s' % prefix, 'C'):
|
|
|
|
|
continue
|
2019-08-09 12:46:07 +00:00
|
|
|
|
code = frommap[key]['code']
|
|
|
|
|
name = frommap[key]['name']
|
2019-08-10 11:37:22 +00:00
|
|
|
|
print(' { QLocale::%s::%s, %s, %s },' % (prefix, key, tochar(name), tochar(code)))
|
2019-08-02 14:07:55 +00:00
|
|
|
|
|
2019-08-07 14:48:16 +00:00
|
|
|
|
# now everything except those but only unique code values
|
2019-08-02 14:07:55 +00:00
|
|
|
|
for key in sorted(frommap.keys()):
|
|
|
|
|
if key in ('Any%s' % prefix, 'C'):
|
|
|
|
|
continue
|
2019-08-09 12:46:07 +00:00
|
|
|
|
code = frommap[key]['code']
|
|
|
|
|
if code in seencodes:
|
2019-08-07 14:48:16 +00:00
|
|
|
|
continue
|
2019-08-09 12:46:07 +00:00
|
|
|
|
seencodes.append(code)
|
|
|
|
|
name = frommap[key]['name']
|
2019-08-10 11:37:22 +00:00
|
|
|
|
print(' { QLocale::%s::%s, %s, %s },' % (prefix, key, tochar(name), tochar(code)))
|
2019-08-02 14:07:55 +00:00
|
|
|
|
|
|
|
|
|
print('};')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
print('static const qint16 %sTblSize = sizeof(%sTbl) / sizeof(%sTblData);\n' % (lowerprefix, lowerprefix, lowerprefix))
|
2019-08-02 14:07:55 +00:00
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
def printlocaledata(frommap, key):
|
|
|
|
|
value = frommap[key]
|
2019-08-06 14:09:10 +00:00
|
|
|
|
# skip table entries without country (non-territory), unless it is artificial, this is done to
|
|
|
|
|
# preserve the assumption in QLocalePrivate::findLocale that "AnyCountry" means "find me a
|
|
|
|
|
# language, no matter what country it is spoken in" if "AnyCountry" is passed to it as argument
|
|
|
|
|
# and also shrinks the table
|
2019-08-07 19:26:34 +00:00
|
|
|
|
if value['country'] == 'QLocale::Country::AnyCountry' and not key == 'C':
|
2019-08-06 14:09:10 +00:00
|
|
|
|
return
|
2019-08-04 15:56:53 +00:00
|
|
|
|
print(''' {
|
|
|
|
|
%s, %s, %s,
|
|
|
|
|
%s, %s, %s,
|
2019-08-09 15:29:13 +00:00
|
|
|
|
%s, %s, %s, %s, %s, %s, %s, %s, %s,
|
2019-08-04 15:56:53 +00:00
|
|
|
|
%s, %s, %s, %s,
|
|
|
|
|
%s, %s,
|
|
|
|
|
%s, %s, %s, %s,
|
|
|
|
|
%s, %s, %s, %s,
|
|
|
|
|
%s, %s,
|
2019-08-09 15:29:13 +00:00
|
|
|
|
%s, %s, %s, %s, %s,
|
2019-08-04 15:56:53 +00:00
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s,
|
|
|
|
|
%s
|
|
|
|
|
}, // %s''' % (
|
|
|
|
|
value['language'],
|
|
|
|
|
value['script'],
|
|
|
|
|
value['country'],
|
|
|
|
|
value['first_day_of_week'],
|
|
|
|
|
value['weekend_start'],
|
|
|
|
|
value['weekend_end'],
|
2019-08-04 20:31:26 +00:00
|
|
|
|
touint(value['decimal']),
|
|
|
|
|
touint(value['group']),
|
|
|
|
|
touint(value['list']),
|
|
|
|
|
touint(value['percent']),
|
|
|
|
|
touint(value['minus']),
|
|
|
|
|
touint(value['plus']),
|
|
|
|
|
touint(value['exponential']),
|
2019-08-04 15:56:53 +00:00
|
|
|
|
value['currency_digits'],
|
2019-08-04 20:31:26 +00:00
|
|
|
|
touint(value['zero']),
|
2019-08-09 14:52:38 +00:00
|
|
|
|
touint(value['quotation_start']),
|
|
|
|
|
touint(value['quotation_end']),
|
|
|
|
|
touint(value['alternate_quotation_start']),
|
|
|
|
|
touint(value['alternate_quotation_end']),
|
2019-08-04 18:23:29 +00:00
|
|
|
|
tochar(value['language_endonym']),
|
|
|
|
|
tochar(value['country_endonym']),
|
|
|
|
|
tochar(value['list_pattern_part_start']),
|
|
|
|
|
tochar(value['list_pattern_part_mid']),
|
|
|
|
|
tochar(value['list_pattern_part_end']),
|
|
|
|
|
tochar(value['list_pattern_part_two']),
|
2019-08-12 00:50:49 +00:00
|
|
|
|
tochar(value['short_date_format']),
|
|
|
|
|
tochar(value['long_date_format']),
|
2019-08-04 18:23:29 +00:00
|
|
|
|
tochar(value['short_time_format']),
|
|
|
|
|
tochar(value['long_time_format']),
|
|
|
|
|
tochar(value['am']),
|
|
|
|
|
tochar(value['pm']),
|
|
|
|
|
tochar(value['currency_symbol']),
|
|
|
|
|
tochar(value['currency_format']),
|
|
|
|
|
tochar(value['currency_negative_format']),
|
|
|
|
|
tochar(value['currency_iso_code']),
|
2019-08-09 15:29:13 +00:00
|
|
|
|
tochar(value['currency_display_name']),
|
2019-08-04 18:23:29 +00:00
|
|
|
|
tochararray(value['standalone_short_month_names']),
|
|
|
|
|
tochararray(value['standalone_long_month_names']),
|
|
|
|
|
tochararray(value['standalone_narrow_month_names']),
|
|
|
|
|
tochararray(value['short_month_names']),
|
|
|
|
|
tochararray(value['long_month_names']),
|
|
|
|
|
tochararray(value['narrow_month_names']),
|
|
|
|
|
tochararray(value['standalone_short_day_names']),
|
|
|
|
|
tochararray(value['standalone_long_day_names']),
|
|
|
|
|
tochararray(value['standalone_narrow_day_names']),
|
|
|
|
|
tochararray(value['short_day_names']),
|
|
|
|
|
tochararray(value['long_day_names']),
|
|
|
|
|
tochararray(value['narrow_day_names']),
|
2019-08-04 15:56:53 +00:00
|
|
|
|
key,
|
|
|
|
|
)
|
|
|
|
|
)
|
2019-08-02 14:07:55 +00:00
|
|
|
|
|
2019-08-10 19:15:18 +00:00
|
|
|
|
def printaliastable(frommap, prefix):
|
|
|
|
|
print('''static const struct %sAliasTblData {
|
|
|
|
|
const QLatin1String original;
|
|
|
|
|
const QLatin1String substitute;
|
|
|
|
|
} %sAliasTbl[] = {''' % (prefix, prefix))
|
|
|
|
|
|
|
|
|
|
for key in sorted(frommap):
|
|
|
|
|
# territories and scripts entries can contain multiple replacements, add one for each
|
|
|
|
|
splitvalue = frommap[key].split(' ')
|
|
|
|
|
for value in splitvalue:
|
|
|
|
|
print(' { QLatin1String("%s"), QLatin1String("%s") },' % (key, value))
|
|
|
|
|
|
|
|
|
|
print('};')
|
|
|
|
|
print('static const qint16 %sAliasTblSize = sizeof(%sAliasTbl) / sizeof(%sAliasTblData);\n' % (prefix, prefix, prefix))
|
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# main maps
|
|
|
|
|
languagemap = {}
|
|
|
|
|
countrymap = {}
|
|
|
|
|
scriptmap = {}
|
|
|
|
|
localemap = {}
|
2019-08-10 19:15:18 +00:00
|
|
|
|
likelysubtagsmap = {}
|
2019-08-09 17:39:01 +00:00
|
|
|
|
languagealiasmap = {}
|
2019-08-10 19:15:18 +00:00
|
|
|
|
countryaliasmap = {}
|
|
|
|
|
scriptaliasmap = {}
|
2019-08-04 19:27:41 +00:00
|
|
|
|
# main lists
|
|
|
|
|
imperiallist = []
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# cross-reference maps
|
2019-08-05 22:00:18 +00:00
|
|
|
|
localeparentmap = {}
|
|
|
|
|
localeparentvaluesmap = {}
|
2019-08-04 15:56:53 +00:00
|
|
|
|
localescriptmap = {}
|
|
|
|
|
localefirstdaymap = {}
|
2019-08-05 16:33:01 +00:00
|
|
|
|
localeweekendstartmap = {}
|
|
|
|
|
localeweekendendmap = {}
|
2019-08-04 15:56:53 +00:00
|
|
|
|
localeiso4217map = {}
|
|
|
|
|
localecurrencymap = {}
|
2019-08-06 11:27:12 +00:00
|
|
|
|
localenumberingmap = {}
|
2019-08-10 19:15:18 +00:00
|
|
|
|
# regular expressions
|
|
|
|
|
localeregex = re.compile('([^_|-|\.|@]+)+')
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-05 18:28:49 +00:00
|
|
|
|
# artificial entries
|
2019-08-09 12:46:07 +00:00
|
|
|
|
languagemap['AnyLanguage'] = {
|
|
|
|
|
'code': '',
|
|
|
|
|
'name': 'Default',
|
|
|
|
|
}
|
|
|
|
|
languagemap['C'] = {
|
|
|
|
|
'code': 'C',
|
|
|
|
|
'name': 'C',
|
|
|
|
|
}
|
|
|
|
|
countrymap['AnyCountry'] = {
|
|
|
|
|
'code': '',
|
|
|
|
|
'name': 'Default',
|
|
|
|
|
}
|
|
|
|
|
scriptmap['AnyScript'] = {
|
|
|
|
|
'code': '',
|
|
|
|
|
'name': 'Default',
|
|
|
|
|
}
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-05 22:00:18 +00:00
|
|
|
|
# locale to parent parsing
|
2019-08-04 15:56:53 +00:00
|
|
|
|
tree = ET.parse('common/supplemental/supplementalData.xml')
|
|
|
|
|
root = tree.getroot()
|
2019-08-05 22:00:18 +00:00
|
|
|
|
for parentlocale in root.findall('./parentLocales/parentLocale'):
|
|
|
|
|
parentlocaleparent = parentlocale.get('parent')
|
|
|
|
|
parentlocalelocales = parentlocale.get('locales')
|
|
|
|
|
localeparentmap[parentlocaleparent] = parentlocalelocales.split(' ')
|
|
|
|
|
|
|
|
|
|
# locale to script parsing
|
2019-08-09 12:46:07 +00:00
|
|
|
|
# only languages with one primary script are mapped because if there are multiple it should be
|
|
|
|
|
# specified in the locale data, see:
|
|
|
|
|
# https://sites.google.com/site/cldr/development/updating-codes/update-language-script-info/language-script-description
|
2019-08-09 17:39:01 +00:00
|
|
|
|
# secondary scripts are not taken into account at all
|
2019-08-04 19:27:41 +00:00
|
|
|
|
for suppllanguage in root.findall('./languageData/language'):
|
|
|
|
|
suppllanguagetype = suppllanguage.get('type')
|
|
|
|
|
suppllanguagescripts = suppllanguage.get('scripts')
|
2019-08-09 12:46:07 +00:00
|
|
|
|
suppllanguagealt = suppllanguage.get('alt')
|
|
|
|
|
if not suppllanguagescripts or suppllanguagealt == 'secondary':
|
2019-08-08 21:41:52 +00:00
|
|
|
|
# alternative entry, skip it
|
|
|
|
|
continue
|
2019-08-09 12:46:07 +00:00
|
|
|
|
suppllanguagescriptslist = suppllanguagescripts.split(' ')
|
|
|
|
|
if not len(suppllanguagescriptslist) == 1:
|
|
|
|
|
# skip entries without definitive primary script
|
|
|
|
|
continue
|
|
|
|
|
suppllanguageterritories = suppllanguage.get('territories')
|
|
|
|
|
if not suppllanguageterritories:
|
|
|
|
|
# territories is optional, if not specified use artifical value to map all languages of
|
|
|
|
|
# that type to the script
|
|
|
|
|
suppllanguageterritories = 'AnyTerritory'
|
|
|
|
|
localescriptmap[suppllanguagetype] = {
|
|
|
|
|
'script': suppllanguagescripts,
|
|
|
|
|
'territories': suppllanguageterritories.split(' '),
|
|
|
|
|
}
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-04 18:23:29 +00:00
|
|
|
|
# locale to first day parsing
|
2019-08-04 15:56:53 +00:00
|
|
|
|
for firstday in root.findall('./weekData/firstDay'):
|
|
|
|
|
firstdayday = firstday.get('day')
|
|
|
|
|
firstdayterritories = firstday.get('territories')
|
2019-08-04 18:23:29 +00:00
|
|
|
|
localefirstdaymap[todayenum(firstdayday)] = stripxmltext(firstdayterritories).split(' ')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-05 16:33:01 +00:00
|
|
|
|
# locale to weekend start parsing
|
2019-08-04 15:56:53 +00:00
|
|
|
|
for weekstart in root.findall('./weekData/weekendStart'):
|
|
|
|
|
weekstartday = weekstart.get('day')
|
|
|
|
|
weekstartterritories = weekstart.get('territories')
|
2019-08-05 16:33:01 +00:00
|
|
|
|
localeweekendstartmap[todayenum(weekstartday)] = stripxmltext(weekstartterritories).split(' ')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-05 16:33:01 +00:00
|
|
|
|
# locale to weekend end parsing
|
|
|
|
|
for weekend in root.findall('./weekData/weekendEnd'):
|
2019-08-04 15:56:53 +00:00
|
|
|
|
weekendday = weekend.get('day')
|
|
|
|
|
weekendterritories = weekend.get('territories')
|
2019-08-05 16:33:01 +00:00
|
|
|
|
localeweekendendmap[todayenum(weekendday)] = stripxmltext(weekendterritories).split(' ')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-04 18:23:29 +00:00
|
|
|
|
# locale to iso4217 parsing
|
2019-08-04 15:56:53 +00:00
|
|
|
|
for region in root.findall('./currencyData/region'):
|
|
|
|
|
regioniso3166 = region.get('iso3166')
|
2019-08-07 19:26:34 +00:00
|
|
|
|
# data includes past currencies too, pick the current currency which is first
|
|
|
|
|
currency = region.find('currency')
|
|
|
|
|
currencyiso4217 = currency.get('iso4217')
|
|
|
|
|
localeiso4217map[regioniso3166] = currencyiso4217
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-04 18:23:29 +00:00
|
|
|
|
# locale to currency parsing
|
2019-08-04 15:56:53 +00:00
|
|
|
|
for info in root.findall('./currencyData/fractions/info'):
|
|
|
|
|
infoiso4217 = info.get('iso4217')
|
|
|
|
|
infodigits = info.get('digits')
|
2019-08-09 15:29:13 +00:00
|
|
|
|
localecurrencymap[infoiso4217] = infodigits
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-06 11:27:12 +00:00
|
|
|
|
# locale to numbering system parsing
|
2019-08-04 15:56:53 +00:00
|
|
|
|
tree = ET.parse('common/supplemental/numberingSystems.xml')
|
|
|
|
|
root = tree.getroot()
|
2019-08-06 11:27:12 +00:00
|
|
|
|
for numberingsystem in root.findall('./numberingSystems/numberingSystem'):
|
|
|
|
|
numberingsystemid = numberingsystem.get('id')
|
|
|
|
|
numberingsystemdigits = numberingsystem.get('digits')
|
|
|
|
|
if numberingsystemdigits:
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# either digits or rules is set
|
2019-08-06 11:27:12 +00:00
|
|
|
|
localenumberingmap[numberingsystemid] = stripxmltext(numberingsystemdigits)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
# language parsing
|
|
|
|
|
tree = ET.parse('common/main/en.xml')
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
for language in root.findall('./localeDisplayNames/languages/language'):
|
|
|
|
|
languagetype = language.get('type')
|
|
|
|
|
normallanguage = normalizestring(language.text)
|
|
|
|
|
if normallanguage in ('Nauru', 'Tokelau', 'Tuvalu'):
|
2019-08-09 17:39:01 +00:00
|
|
|
|
# country and language are the same, suffix to solve enum clashes
|
2019-08-04 15:56:53 +00:00
|
|
|
|
normallanguage = '%sLanguage' % normallanguage
|
2019-08-09 12:46:07 +00:00
|
|
|
|
languagemap[normallanguage] = {
|
|
|
|
|
'code': languagetype,
|
|
|
|
|
'name': language.text,
|
|
|
|
|
}
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-07 13:53:57 +00:00
|
|
|
|
if printenumsandexit:
|
|
|
|
|
printenum(languagemap, 'Language')
|
|
|
|
|
else:
|
|
|
|
|
printtable(languagemap, 'Language')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
# country parsing
|
|
|
|
|
for country in root.findall('./localeDisplayNames/territories/territory'):
|
|
|
|
|
countrytype = country.get('type')
|
|
|
|
|
normalcountry = normalizestring(country.text)
|
2019-08-09 12:46:07 +00:00
|
|
|
|
countrymap[normalcountry] = {
|
|
|
|
|
'code': countrytype,
|
|
|
|
|
'name': country.text,
|
|
|
|
|
}
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-07 13:53:57 +00:00
|
|
|
|
if printenumsandexit:
|
|
|
|
|
printenum(countrymap, 'Country')
|
|
|
|
|
else:
|
|
|
|
|
printtable(countrymap, 'Country')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
# scripts parsing
|
|
|
|
|
for script in root.findall('./localeDisplayNames/scripts/script'):
|
|
|
|
|
scripttype = script.get('type')
|
|
|
|
|
normalscript = normalizestring(script.text)
|
|
|
|
|
if not normalscript.endswith('Script'):
|
|
|
|
|
# suffix script if needed
|
|
|
|
|
normalscript = '%sScript' % normalscript
|
|
|
|
|
if normalscript in ('UnknownScript', 'CommonScript'):
|
|
|
|
|
# only interested in specific scripts
|
|
|
|
|
continue
|
2019-08-09 12:46:07 +00:00
|
|
|
|
scriptmap[normalscript] = {
|
|
|
|
|
'code': scripttype,
|
|
|
|
|
'name': script.text,
|
|
|
|
|
}
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-07 13:53:57 +00:00
|
|
|
|
if printenumsandexit:
|
|
|
|
|
printenum(scriptmap, 'Script')
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
else:
|
|
|
|
|
printtable(scriptmap, 'Script')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-07 19:26:34 +00:00
|
|
|
|
# these defaults are used as parent locales fallback, C uses them as actual values because root
|
|
|
|
|
# contains UTF-8 characters and for compatibility. for the rest defaults are set from root
|
2019-08-04 15:56:53 +00:00
|
|
|
|
localedefaults = {
|
|
|
|
|
# enums
|
|
|
|
|
'language': 'QLocale::Language::AnyLanguage',
|
|
|
|
|
'script': 'QLocale::Script::AnyScript',
|
|
|
|
|
'country': 'QLocale::Country::AnyCountry',
|
|
|
|
|
'first_day_of_week': 'Qt::Monday',
|
|
|
|
|
'weekend_start': 'Qt::Saturday',
|
|
|
|
|
'weekend_end': 'Qt::Sunday',
|
|
|
|
|
# characters
|
|
|
|
|
'decimal': '.',
|
|
|
|
|
'group': ',',
|
|
|
|
|
'list': ';',
|
|
|
|
|
'percent': '%',
|
|
|
|
|
'zero': '0',
|
|
|
|
|
'minus': '-',
|
|
|
|
|
'plus': '+',
|
|
|
|
|
'exponential': 'e', # default in CLDR is E
|
|
|
|
|
'currency_digits': '2',
|
2019-08-06 18:04:00 +00:00
|
|
|
|
'quotation_start': '"', # default in CLDR is “
|
|
|
|
|
'quotation_end': '"', # default in CLDR is ”
|
|
|
|
|
'alternate_quotation_start': "'", # default in CLDR is ‘
|
|
|
|
|
'alternate_quotation_end': "'", # default in CLDR is ’
|
2019-08-09 17:39:01 +00:00
|
|
|
|
# strings
|
2019-08-04 15:56:53 +00:00
|
|
|
|
'language_endonym': '',
|
|
|
|
|
'country_endonym': '',
|
|
|
|
|
'list_pattern_part_start': "%1, %2",
|
|
|
|
|
'list_pattern_part_mid': "%1, %2",
|
|
|
|
|
'list_pattern_part_end': "%1, %2",
|
|
|
|
|
'list_pattern_part_two': "%1, %2",
|
2019-08-08 11:21:20 +00:00
|
|
|
|
'short_date_format': 'd MMM yyyy', # default in CLDR is y-MM-dd
|
2019-08-05 01:32:21 +00:00
|
|
|
|
'long_date_format': 'd MMMM yyyy',
|
2019-08-09 12:46:07 +00:00
|
|
|
|
'short_time_format': 'HH:mm:ss', # default in CLDR is HH:mm
|
2019-08-04 15:56:53 +00:00
|
|
|
|
'long_time_format': 'HH:mm:ss z',
|
|
|
|
|
'am': 'AM',
|
|
|
|
|
'pm': 'PM',
|
|
|
|
|
'currency_symbol': '',
|
|
|
|
|
'currency_format': '%1%2',
|
|
|
|
|
'currency_negative_format': '',
|
|
|
|
|
'currency_iso_code': '',
|
2019-08-09 15:29:13 +00:00
|
|
|
|
'currency_display_name': '',
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# arrays
|
|
|
|
|
'standalone_short_month_names': ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
|
|
|
|
'standalone_long_month_names': ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
|
|
|
|
'standalone_narrow_month_names': ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
|
|
|
|
|
'short_month_names': ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
|
|
|
|
'long_month_names': ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
|
|
|
|
'narrow_month_names': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
|
2019-08-12 11:46:53 +00:00
|
|
|
|
'standalone_short_day_names': ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
|
|
|
'standalone_long_day_names': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
|
|
|
|
'standalone_narrow_day_names': ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
|
|
|
|
|
'short_day_names': ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
|
|
|
'long_day_names': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
|
|
|
|
'narrow_day_names': ['1', '2', '3', '4', '5', '6', '7'],
|
2019-08-04 15:56:53 +00:00
|
|
|
|
}
|
2019-08-06 19:36:36 +00:00
|
|
|
|
# artificial entries
|
2019-08-04 15:56:53 +00:00
|
|
|
|
localemap['C'] = {}
|
2019-08-06 19:36:36 +00:00
|
|
|
|
mapcopy(localedefaults, localemap['C'])
|
|
|
|
|
localemap['C']['language'] = 'QLocale::Language::C'
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-06 18:22:12 +00:00
|
|
|
|
# locales parsing
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# TODO: accept only "contributed" or "approved" values
|
2019-08-05 22:00:18 +00:00
|
|
|
|
def readlocale(fromxml, tomap, isparent):
|
2019-08-11 12:03:33 +00:00
|
|
|
|
locale = os.path.basename(fromxml)
|
|
|
|
|
locale = locale.replace('.xml', '')
|
|
|
|
|
|
|
|
|
|
if '_' in fromxml:
|
2019-08-11 22:08:29 +00:00
|
|
|
|
# merge parent locales (non-territory) into the current one so that data can be read
|
2019-08-11 12:03:33 +00:00
|
|
|
|
# from them. they do not have territory and currency data is based on territory so
|
|
|
|
|
# cross-reference is not possible without doing so
|
|
|
|
|
localeparent = locale.split('_')[0]
|
|
|
|
|
xmlparent = fromxml.replace(locale, localeparent)
|
|
|
|
|
root = xmlmerge(fromxml, xmlparent)
|
|
|
|
|
else:
|
|
|
|
|
tree = ET.parse(fromxml)
|
|
|
|
|
root = tree.getroot()
|
2019-08-05 20:24:01 +00:00
|
|
|
|
|
|
|
|
|
variant = root.find('./identity/variant')
|
|
|
|
|
if variant is not None:
|
2019-08-05 20:27:33 +00:00
|
|
|
|
# TODO: variants are not supported by QLocale
|
2019-08-05 22:00:18 +00:00
|
|
|
|
return
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
language = root.find('./identity/language')
|
2019-08-05 19:47:38 +00:00
|
|
|
|
langtype = language.get('type')
|
2019-08-05 22:24:47 +00:00
|
|
|
|
country = root.find('./identity/territory')
|
2019-08-04 15:56:53 +00:00
|
|
|
|
countrytype = None
|
|
|
|
|
currencytype = None
|
2019-08-08 21:41:52 +00:00
|
|
|
|
scripttype = None
|
2019-08-04 18:23:29 +00:00
|
|
|
|
numbertype = 'latn' # CLDR default
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale] = {}
|
2019-08-06 18:22:12 +00:00
|
|
|
|
if isparent:
|
|
|
|
|
mapcopy(localedefaults, tomap[locale])
|
|
|
|
|
else:
|
|
|
|
|
mapcopy(localeparentvaluesmap['root'], tomap[locale])
|
2019-08-05 22:00:18 +00:00
|
|
|
|
|
2019-08-05 22:24:47 +00:00
|
|
|
|
# set defaults from parent locale if territory is specified
|
2019-08-05 19:47:38 +00:00
|
|
|
|
if country is not None:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
for parent in localeparentmap.keys():
|
2019-08-05 22:24:47 +00:00
|
|
|
|
if locale in localeparentmap[parent]:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
mapcopy(localeparentvaluesmap[parent], tomap[locale])
|
2019-08-05 22:24:47 +00:00
|
|
|
|
# then from main locale (non-territory) filling the blanks that even parent locales do not fill
|
2019-08-05 22:00:18 +00:00
|
|
|
|
if not isparent:
|
2019-08-05 22:24:47 +00:00
|
|
|
|
mapmerge(localemap[langtype], tomap[locale], localedefaults)
|
2019-08-05 19:47:38 +00:00
|
|
|
|
|
2019-08-04 20:31:26 +00:00
|
|
|
|
# find the enums from mapped values
|
2019-08-10 19:15:18 +00:00
|
|
|
|
tomap[locale]['language'] = tolanguageenum(langtype)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-10 19:15:18 +00:00
|
|
|
|
if not isparent and country is not None:
|
2019-08-01 18:08:02 +00:00
|
|
|
|
countrytype = country.get('type')
|
2019-08-10 19:15:18 +00:00
|
|
|
|
tomap[locale]['country'] = tocountryenum(countrytype)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
else:
|
|
|
|
|
# territory often is not specified, use language code as fallback
|
|
|
|
|
countrytype = langtype.upper()
|
|
|
|
|
|
2019-08-09 12:46:07 +00:00
|
|
|
|
# script is specified either in the locale or supplemental data
|
|
|
|
|
script = root.find('./identity/script')
|
|
|
|
|
if script is not None:
|
|
|
|
|
scripttype = script.get('type')
|
|
|
|
|
elif not isparent:
|
|
|
|
|
# scripts map is partial, pick from what is mapped
|
|
|
|
|
if langtype in localescriptmap.keys():
|
|
|
|
|
scriptterritories = localescriptmap[langtype]['territories']
|
|
|
|
|
if 'AnyTerritory' in scriptterritories \
|
|
|
|
|
or countrytype in scriptterritories:
|
|
|
|
|
scripttype = localescriptmap[langtype]['script']
|
|
|
|
|
|
2019-08-11 12:03:33 +00:00
|
|
|
|
# store for later
|
2019-08-04 15:56:53 +00:00
|
|
|
|
if countrytype in localeiso4217map.keys():
|
|
|
|
|
currencytype = localeiso4217map[countrytype]
|
|
|
|
|
|
|
|
|
|
defaultnumbersystem = root.find('./numbers/defaultNumberingSystem')
|
|
|
|
|
if defaultnumbersystem is not None:
|
2019-08-04 18:23:29 +00:00
|
|
|
|
numbertype = defaultnumbersystem.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-04 19:27:41 +00:00
|
|
|
|
# find values from supplemental maps
|
2019-08-09 12:46:07 +00:00
|
|
|
|
if not isparent and scripttype:
|
2019-08-10 19:15:18 +00:00
|
|
|
|
tomap[locale]['script'] = toscriptenum(scripttype)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-05 22:00:18 +00:00
|
|
|
|
for key in localefirstdaymap.keys():
|
|
|
|
|
for countryvalue in localefirstdaymap[key]:
|
|
|
|
|
if countryvalue == countrytype:
|
|
|
|
|
tomap[locale]['first_day_of_week'] = key
|
|
|
|
|
break
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-05 22:00:18 +00:00
|
|
|
|
for key in localeweekendstartmap.keys():
|
|
|
|
|
for countryvalue in localeweekendstartmap[key]:
|
|
|
|
|
if countryvalue == countrytype:
|
|
|
|
|
tomap[locale]['weekend_start'] = key
|
|
|
|
|
break
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-05 22:00:18 +00:00
|
|
|
|
for key in localeweekendendmap.keys():
|
|
|
|
|
for countryvalue in localeweekendendmap[key]:
|
|
|
|
|
if countryvalue == countrytype:
|
|
|
|
|
tomap[locale]['weekend_end'] = key
|
|
|
|
|
break
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-04 18:23:29 +00:00
|
|
|
|
# find from locale data
|
2019-08-04 15:56:53 +00:00
|
|
|
|
for symbol in root.findall('./numbers/symbols'):
|
|
|
|
|
symbolnumbersystem = symbol.get('numberSystem')
|
2019-08-04 18:23:29 +00:00
|
|
|
|
if not symbolnumbersystem == numbertype:
|
|
|
|
|
# should be the locale numeric system
|
2019-08-01 18:08:02 +00:00
|
|
|
|
continue
|
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
decimal = symbol.find('./decimal')
|
|
|
|
|
if decimal is not None and len(decimal.text) == 1:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['decimal'] = decimal.text
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
group = symbol.find('./group')
|
|
|
|
|
if group is not None and len(group.text) == 1:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['group'] = group.text
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
listdelimiter = symbol.find('./list')
|
|
|
|
|
if listdelimiter is not None and len(listdelimiter.text) == 1:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['list'] = listdelimiter.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
percent = symbol.find('./percentSign')
|
|
|
|
|
if percent is not None and len(percent.text) == 1:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['percent'] = percent.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
minus = symbol.find('./minusSign')
|
|
|
|
|
if minus is not None and len(minus.text) == 1:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['minus'] = minus.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
plus = symbol.find('./plusSign')
|
|
|
|
|
if plus is not None and len(plus.text) == 1:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['plus'] = plus.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
exponential = symbol.find('./exponential')
|
|
|
|
|
if exponential is not None and len(exponential.text) == 1:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['exponential'] = exponential.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-04 20:31:26 +00:00
|
|
|
|
# zero is from cross-reference numeric system map,
|
|
|
|
|
# taking the first character works even for UTF-8 chars
|
2019-08-06 11:27:12 +00:00
|
|
|
|
tomap[locale]['zero'] = localenumberingmap[numbertype][0]
|
2019-08-04 20:31:26 +00:00
|
|
|
|
|
2019-08-07 19:26:34 +00:00
|
|
|
|
# locale numeric system was found, break
|
|
|
|
|
break
|
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# digits/rounding data is specific so check if it is mapped
|
|
|
|
|
if currencytype and currencytype in localecurrencymap.keys():
|
2019-08-09 15:29:13 +00:00
|
|
|
|
tomap[locale]['currency_digits'] = localecurrencymap[currencytype]
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
quotationstart = root.find('./delimiters/quotationStart')
|
|
|
|
|
if quotationstart is not None:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['quotation_start'] = quotationstart.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
quotationend = root.find('./delimiters/quotationEnd')
|
|
|
|
|
if quotationend is not None:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['quotation_end'] = quotationend.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
altquotationstart = root.find('./delimiters/alternateQuotationStart')
|
|
|
|
|
if altquotationstart is not None:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['alternate_quotation_start'] = altquotationstart.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
altquotationend = root.find('./delimiters/alternateQuotationEnd')
|
|
|
|
|
if altquotationend is not None:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['alternate_quotation_end'] = altquotationend.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-06 11:27:12 +00:00
|
|
|
|
for nativelang in root.findall('./localeDisplayNames/languages/language'):
|
|
|
|
|
nativelangtype = nativelang.get('type')
|
|
|
|
|
if nativelangtype == langtype:
|
|
|
|
|
tomap[locale]['language_endonym'] = nativelang.text
|
|
|
|
|
break
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
if countrytype:
|
|
|
|
|
for nativecountry in root.findall('./localeDisplayNames/territories/territory'):
|
|
|
|
|
nativecountrytype = nativecountry.get('type')
|
|
|
|
|
if nativecountrytype == countrytype:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['country_endonym'] = nativecountry.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
listpattern = root.find('./listPatterns/listPattern')
|
|
|
|
|
if listpattern is not None:
|
|
|
|
|
for listpatternpart in listpattern.findall('./listPatternPart'):
|
|
|
|
|
listpatternparttype = listpatternpart.get('type')
|
|
|
|
|
if listpatternparttype == 'start':
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['list_pattern_part_start'] = tolistformat(listpatternpart.text)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif listpatternparttype == 'middle':
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['list_pattern_part_mid'] = tolistformat(listpatternpart.text)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif listpatternparttype == 'end':
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['list_pattern_part_end'] = tolistformat(listpatternpart.text)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif listpatternparttype == '2':
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['list_pattern_part_two'] = tolistformat(listpatternpart.text)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
for calendar in root.findall('./dates/calendars/calendar'):
|
|
|
|
|
calendartype = calendar.get('type')
|
|
|
|
|
if not calendartype == 'gregorian':
|
2019-08-06 11:27:12 +00:00
|
|
|
|
# all values should be from gregorian calendar
|
2019-08-02 14:07:55 +00:00
|
|
|
|
continue
|
2019-08-08 11:21:20 +00:00
|
|
|
|
for dateformat in calendar.findall('./dateFormats/dateFormatLength'):
|
2019-08-04 15:56:53 +00:00
|
|
|
|
dateformattype = dateformat.get('type')
|
|
|
|
|
if dateformattype == 'short':
|
|
|
|
|
pattern = dateformat.find('./dateFormat/pattern')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['short_date_format'] = todatetimeformat(pattern.text)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif dateformattype == 'long':
|
|
|
|
|
pattern = dateformat.find('./dateFormat/pattern')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['long_date_format'] = todatetimeformat(pattern.text)
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-08 11:21:20 +00:00
|
|
|
|
for timeformat in calendar.findall('./timeFormats/timeFormatLength'):
|
2019-08-04 15:56:53 +00:00
|
|
|
|
timeformattype = timeformat.get('type')
|
|
|
|
|
if timeformattype == 'short':
|
|
|
|
|
pattern = timeformat.find('./timeFormat/pattern')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['short_time_format'] = todatetimeformat(pattern.text)
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif timeformattype == 'long':
|
|
|
|
|
pattern = timeformat.find('./timeFormat/pattern')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['long_time_format'] = todatetimeformat(pattern.text)
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
for dayperiodwidth in calendar.findall('./dayPeriods/dayPeriodContext/dayPeriodWidth'):
|
|
|
|
|
dayperiodwidthtype = dayperiodwidth.get('type')
|
|
|
|
|
if not dayperiodwidthtype == 'wide':
|
2019-08-06 11:27:12 +00:00
|
|
|
|
# all values should be in wide format
|
2019-08-04 15:56:53 +00:00
|
|
|
|
continue
|
|
|
|
|
for dayperiod in dayperiodwidth.findall('dayPeriod'):
|
|
|
|
|
dayperiodtype = dayperiod.get('type')
|
|
|
|
|
if dayperiodtype == 'am':
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['am'] = dayperiod.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif dayperiodtype == 'pm':
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['pm'] = dayperiod.text
|
2019-08-01 18:08:02 +00:00
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# month/day names
|
|
|
|
|
for monthcontext in calendar.findall('./months/monthContext'):
|
|
|
|
|
monthcontexttype = monthcontext.get('type')
|
|
|
|
|
if monthcontexttype == 'stand-alone':
|
|
|
|
|
for monthwidth in monthcontext.findall('./monthWidth'):
|
|
|
|
|
monthwidthtype = monthwidth.get('type')
|
|
|
|
|
if monthwidthtype == 'wide':
|
|
|
|
|
months = monthwidth.findall('./month')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['standalone_long_month_names'] = tomonthslist(months, tomap[locale]['standalone_long_month_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif monthwidthtype == 'abbreviated':
|
|
|
|
|
months = monthwidth.findall('./month')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['standalone_short_month_names'] = tomonthslist(months, tomap[locale]['standalone_short_month_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif monthwidthtype == 'narrow':
|
|
|
|
|
months = monthwidth.findall('./month')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['standalone_narrow_month_names'] = tomonthslist(months, tomap[locale]['standalone_narrow_month_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif monthcontexttype == 'format':
|
|
|
|
|
for monthwidth in monthcontext.findall('./monthWidth'):
|
|
|
|
|
monthwidthtype = monthwidth.get('type')
|
|
|
|
|
if monthwidthtype == 'wide':
|
|
|
|
|
months = monthwidth.findall('./month')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['long_month_names'] = tomonthslist(months, tomap[locale]['long_month_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif monthwidthtype == 'abbreviated':
|
|
|
|
|
months = monthwidth.findall('./month')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['short_month_names'] = tomonthslist(months, tomap[locale]['short_month_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif monthwidthtype == 'narrow':
|
|
|
|
|
months = monthwidth.findall('./month')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['narrow_month_names'] = tomonthslist(months, tomap[locale]['narrow_month_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
for daycontext in calendar.findall('./days/dayContext'):
|
|
|
|
|
daycontexttype = daycontext.get('type')
|
|
|
|
|
if daycontexttype == 'stand-alone':
|
|
|
|
|
for daywidth in daycontext.findall('./dayWidth'):
|
|
|
|
|
daywidthtype = daywidth.get('type')
|
|
|
|
|
if daywidthtype == 'wide':
|
|
|
|
|
days = daywidth.findall('./day')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['standalone_long_day_names'] = todayslist(days, tomap[locale]['standalone_long_day_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daywidthtype == 'abbreviated':
|
|
|
|
|
days = daywidth.findall('./day')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['standalone_short_day_names'] = todayslist(days, tomap[locale]['standalone_short_day_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daywidthtype == 'narrow':
|
|
|
|
|
days = daywidth.findall('./day')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['standalone_narrow_day_names'] = todayslist(days, tomap[locale]['standalone_narrow_day_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daycontexttype == 'format':
|
|
|
|
|
for daywidth in daycontext.findall('./dayWidth'):
|
|
|
|
|
daywidthtype = daywidth.get('type')
|
|
|
|
|
if daywidthtype == 'wide':
|
|
|
|
|
days = daywidth.findall('./day')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['long_day_names'] = todayslist(days, tomap[locale]['long_day_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daywidthtype == 'abbreviated':
|
|
|
|
|
days = daywidth.findall('./day')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['short_day_names'] = todayslist(days, tomap[locale]['short_day_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
elif daywidthtype == 'narrow':
|
|
|
|
|
days = daywidth.findall('./day')
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['narrow_day_names'] = todayslist(days, tomap[locale]['narrow_day_names'])
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
# gregorian calendar was found, break
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if currencytype:
|
|
|
|
|
for elemcurrency in root.findall('./numbers/currencies/currency'):
|
|
|
|
|
elemcurrencytype = elemcurrency.get('type')
|
|
|
|
|
if elemcurrencytype == currencytype:
|
|
|
|
|
symbol = elemcurrency.find('./symbol')
|
|
|
|
|
if symbol is not None:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['currency_symbol'] = symbol.text
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
for displayname in elemcurrency.findall('./displayName'):
|
|
|
|
|
displaynamecount = displayname.get('count')
|
|
|
|
|
if not displaynamecount:
|
2019-08-09 15:29:13 +00:00
|
|
|
|
# only interested in default display name
|
|
|
|
|
tomap[locale]['currency_display_name'] = displayname.text
|
|
|
|
|
break
|
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
# currency type was found, break
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
for currencyformat in root.findall('./numbers/currencyFormats'):
|
|
|
|
|
currencyformatnumbersystem = currencyformat.get('numberSystem')
|
2019-08-04 18:23:29 +00:00
|
|
|
|
if not currencyformatnumbersystem == numbertype:
|
|
|
|
|
# should be the locale numeric system
|
2019-08-04 15:56:53 +00:00
|
|
|
|
continue
|
|
|
|
|
nativecurrencyformat = currencyformat.find('currencyFormatLength/currencyFormat/pattern')
|
|
|
|
|
if nativecurrencyformat is not None:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
formats = tocurrencyformat(nativecurrencyformat.text, tomap[locale])
|
|
|
|
|
tomap[locale]['currency_format'] = formats[0]
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-04 18:23:29 +00:00
|
|
|
|
# negative format is optional
|
2019-08-04 15:56:53 +00:00
|
|
|
|
if len(formats) > 1:
|
2019-08-05 22:00:18 +00:00
|
|
|
|
tomap[locale]['currency_negative_format'] = formats[1]
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
2019-08-11 12:03:33 +00:00
|
|
|
|
# currency format was found, break
|
|
|
|
|
break
|
|
|
|
|
|
2019-08-11 10:03:56 +00:00
|
|
|
|
tomap[locale]['currency_iso_code'] = currencytype
|
2019-08-04 15:56:53 +00:00
|
|
|
|
|
|
|
|
|
# month/day names are set during calendar parsing
|
|
|
|
|
|
2019-08-05 22:00:18 +00:00
|
|
|
|
# read parent locales first
|
|
|
|
|
for xml in glob.glob('common/main/*.xml'):
|
|
|
|
|
xmlbase = os.path.basename(xml)
|
|
|
|
|
xmlbase = xmlbase.replace('.xml', '')
|
|
|
|
|
if not xmlbase in localeparentmap.keys():
|
|
|
|
|
continue
|
|
|
|
|
readlocale(xml, localeparentvaluesmap, True)
|
|
|
|
|
|
|
|
|
|
# now everything including those
|
|
|
|
|
for xml in sorted(glob.glob('common/main/*.xml')):
|
|
|
|
|
if xml.endswith('/root.xml'):
|
|
|
|
|
# root is not actual locale
|
|
|
|
|
continue
|
|
|
|
|
readlocale(xml, localemap, False)
|
|
|
|
|
|
2019-08-04 15:56:53 +00:00
|
|
|
|
print('''static const QLocalePrivate localeTbl[] = {''')
|
|
|
|
|
|
2019-08-07 19:26:34 +00:00
|
|
|
|
# print C first
|
2019-08-04 15:56:53 +00:00
|
|
|
|
printlocaledata(localemap, 'C')
|
|
|
|
|
|
2019-08-07 19:26:34 +00:00
|
|
|
|
# now everything except that
|
2019-08-04 15:56:53 +00:00
|
|
|
|
for key in sorted(localemap.keys()):
|
2019-08-07 19:26:34 +00:00
|
|
|
|
if key == 'C':
|
2019-08-04 15:56:53 +00:00
|
|
|
|
continue
|
|
|
|
|
printlocaledata(localemap, key)
|
|
|
|
|
|
|
|
|
|
print('};')
|
2019-08-04 19:27:41 +00:00
|
|
|
|
print('static const qint16 localeTblSize = sizeof(localeTbl) / sizeof(QLocalePrivate);\n')
|
|
|
|
|
|
|
|
|
|
# imperial parsing
|
|
|
|
|
tree = ET.parse('common/supplemental/supplementalData.xml')
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
for measurementsystem in root.findall('./measurementData/measurementSystem'):
|
|
|
|
|
measurementsystemtype = measurementsystem.get('type')
|
|
|
|
|
if measurementsystemtype in ('UK', 'US'):
|
|
|
|
|
territories = measurementsystem.get('territories')
|
|
|
|
|
for territory in territories.split(' '):
|
2019-08-10 20:33:42 +00:00
|
|
|
|
imperiallist.append(tocountryenum(territory))
|
2019-08-04 19:27:41 +00:00
|
|
|
|
|
|
|
|
|
print('''static const QLocale::Country imperialTbl[] = {''')
|
|
|
|
|
|
|
|
|
|
for string in sorted(imperiallist):
|
2019-08-10 20:33:42 +00:00
|
|
|
|
print(' %s,' % string)
|
2019-08-04 19:27:41 +00:00
|
|
|
|
|
|
|
|
|
print('};')
|
2019-08-09 17:39:01 +00:00
|
|
|
|
print('static const qint16 imperialTblSize = sizeof(imperialTbl);\n')
|
|
|
|
|
|
2019-08-10 19:15:18 +00:00
|
|
|
|
# likely subtags parsing
|
|
|
|
|
tree = ET.parse('common/supplemental/likelySubtags.xml')
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
for likelysubtag in root.findall('./likelySubtags/likelySubtag'):
|
|
|
|
|
likelysubtagfrom = likelysubtag.get('from')
|
|
|
|
|
likelysubtagto = likelysubtag.get('to')
|
|
|
|
|
# split code into language, script and country to make it possible to match against regardless
|
|
|
|
|
# of separators and remap to enums so that it is possible to substitute both named and enumed
|
|
|
|
|
# locale searches at the cost of not covering all named cases
|
|
|
|
|
likelysubtagfromsplit = localeregex.findall(likelysubtagfrom)
|
|
|
|
|
likelysubtagfromsplitlen = len(likelysubtagfromsplit)
|
|
|
|
|
likelysubtagtosplit = localeregex.findall(likelysubtagto)
|
2019-08-11 13:32:58 +00:00
|
|
|
|
likelysubtagtosplitlen = len(likelysubtagtosplit)
|
2019-08-10 19:15:18 +00:00
|
|
|
|
likelyfromlanguage = None
|
|
|
|
|
likelyfromscript = None
|
|
|
|
|
likelyfromcountry = None
|
|
|
|
|
if likelysubtagfromsplitlen == 1:
|
|
|
|
|
likelyfromlanguage = tolanguageenum(likelysubtagfromsplit[0])
|
|
|
|
|
likelyfromscript = 'QLocale::Script::AnyScript'
|
|
|
|
|
likelyfromcountry = 'QLocale::Country::AnyCountry'
|
|
|
|
|
elif likelysubtagfromsplitlen == 2:
|
|
|
|
|
likelyfromlanguage = tolanguageenum(likelysubtagfromsplit[0])
|
|
|
|
|
likelyfromscript = 'QLocale::Script::AnyScript'
|
|
|
|
|
likelyfromcountry = tocountryenum(likelysubtagfromsplit[1])
|
|
|
|
|
elif likelysubtagfromsplitlen == 3:
|
|
|
|
|
likelyfromlanguage = tolanguageenum(likelysubtagfromsplit[0])
|
|
|
|
|
likelyfromscript = toscriptenum(likelysubtagfromsplit[1])
|
|
|
|
|
likelyfromcountry = tocountryenum(likelysubtagfromsplit[2])
|
2019-08-11 13:32:58 +00:00
|
|
|
|
elif likelysubtagfromsplitlen > 3 or likelysubtagtosplitlen > 3:
|
2019-08-10 19:15:18 +00:00
|
|
|
|
# the regular expression is intentionally greedy, if there are more than 3 group matches
|
|
|
|
|
# then it is likely a variant and that is not supported case yet
|
|
|
|
|
print(likelysubtagfrom, likelysubtagfromsplit)
|
2019-08-11 13:32:58 +00:00
|
|
|
|
print(likelysubtagto, likelysubtagtosplit)
|
2019-08-10 19:15:18 +00:00
|
|
|
|
sys.exit(1)
|
|
|
|
|
likelytolanguage = tolanguageenum(likelysubtagtosplit[0])
|
|
|
|
|
likelytoscript = toscriptenum(likelysubtagtosplit[1])
|
|
|
|
|
likelytocountry = tocountryenum(likelysubtagtosplit[2])
|
|
|
|
|
|
|
|
|
|
if not likelyfromlanguage or not likelyfromscript or not likelyfromcountry \
|
|
|
|
|
or not likelytolanguage or not likelytoscript or not likelytocountry:
|
|
|
|
|
# if there are no enums for the codes skip the entry
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
likelysubtagsmap[likelysubtagfrom] = {
|
|
|
|
|
'fromlanguage' : likelyfromlanguage,
|
|
|
|
|
'fromscript' : likelyfromscript,
|
|
|
|
|
'fromcountry' : likelyfromcountry,
|
|
|
|
|
'tolanguage' : likelytolanguage,
|
|
|
|
|
'toscript' : likelytoscript,
|
|
|
|
|
'tocountry' : likelytocountry,
|
|
|
|
|
}
|
|
|
|
|
print('''static const struct subtagAliasTblData {
|
|
|
|
|
const QLocale::Language fromlanguage;
|
|
|
|
|
const QLocale::Script fromscript;
|
|
|
|
|
const QLocale::Country fromcountry;
|
|
|
|
|
const QLocale::Language tolanguage;
|
|
|
|
|
const QLocale::Script toscript;
|
|
|
|
|
const QLocale::Country tocountry;
|
|
|
|
|
} subtagAliasTbl[] = {''')
|
|
|
|
|
|
|
|
|
|
for key in sorted(likelysubtagsmap):
|
|
|
|
|
value = likelysubtagsmap[key]
|
|
|
|
|
print(''' {
|
|
|
|
|
%s, %s, %s,
|
|
|
|
|
%s, %s, %s
|
|
|
|
|
},''' % (
|
|
|
|
|
value['fromlanguage'],
|
|
|
|
|
value['fromscript'],
|
|
|
|
|
value['fromcountry'],
|
|
|
|
|
value['tolanguage'],
|
|
|
|
|
value['toscript'],
|
|
|
|
|
value['tocountry'],
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
print('};')
|
|
|
|
|
print('static const qint16 subtagAliasTblSize = sizeof(subtagAliasTbl) / sizeof(subtagAliasTblData);\n')
|
|
|
|
|
|
2019-08-09 17:39:01 +00:00
|
|
|
|
# language alias parsing
|
|
|
|
|
tree = ET.parse('common/supplemental/supplementalMetadata.xml')
|
|
|
|
|
root = tree.getroot()
|
|
|
|
|
for languagealias in root.findall('./metadata/alias/languageAlias'):
|
|
|
|
|
languagealiastype = languagealias.get('type')
|
|
|
|
|
languagealiasreplacement = languagealias.get('replacement')
|
2019-08-10 19:15:18 +00:00
|
|
|
|
if '_' in languagealiastype or '-' in languagealiastype \
|
|
|
|
|
or '_' in languagealiasreplacement or '-' in languagealiasreplacement:
|
2019-08-11 13:32:58 +00:00
|
|
|
|
# if either the original or the substitute is BCP47 code (language and script/country
|
|
|
|
|
# included) skip it because QLocalePrivate::codeToLanguage() should be dealing with
|
|
|
|
|
# language codes only
|
2019-08-10 19:15:18 +00:00
|
|
|
|
continue
|
2019-08-09 17:39:01 +00:00
|
|
|
|
languagealiasmap[languagealiastype] = languagealiasreplacement
|
|
|
|
|
|
2019-08-10 19:15:18 +00:00
|
|
|
|
printaliastable(languagealiasmap, 'language')
|
2019-08-09 17:39:01 +00:00
|
|
|
|
|
2019-08-10 19:15:18 +00:00
|
|
|
|
# country alias parsing
|
|
|
|
|
for territoryalias in root.findall('./metadata/alias/territoryAlias'):
|
|
|
|
|
territoryaliastype = territoryalias.get('type')
|
|
|
|
|
territoryaliasreplacement = territoryalias.get('replacement')
|
|
|
|
|
countryaliasmap[territoryaliastype] = territoryaliasreplacement
|
2019-08-09 17:39:01 +00:00
|
|
|
|
|
2019-08-10 19:15:18 +00:00
|
|
|
|
printaliastable(countryaliasmap, 'country')
|
|
|
|
|
|
|
|
|
|
# script alias parsing
|
|
|
|
|
for scriptalias in root.findall('./metadata/alias/scriptAlias'):
|
|
|
|
|
scriptaliastype = scriptalias.get('type')
|
|
|
|
|
scriptaliasreplacement = scriptalias.get('replacement')
|
|
|
|
|
scriptaliasmap[scriptaliastype] = scriptaliasreplacement
|
|
|
|
|
|
|
|
|
|
printaliastable(scriptaliasmap, 'script')
|