summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2017-05-30 15:50:47 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2017-06-09 08:24:08 +0000
commitebb0212133bd91f1da4931b29eb1d33fb77b1444 (patch)
tree115ca1d5ca8c69b2a5c88a4341a4642418565de1 /util
parent3a569573b2b8e8dc56f0a152afcb48723b682ba8 (diff)
Rework locale serialization and parsing with less repetition
... because copy-and-paste is worth discouraging. Moved code that writes and digests our Q Local XML form of the data into a common class, localexml.Locale, for use by the scripts that write and read it. Hopefully, it'll be easier to keep what's written and read in sync hereafter. Inlined some trivial functions in the process; and only create a day-number mapping dictionary once, instead of once per use. Also made it easier to see which attributes get which special handling (and documented this); and revised an assertion to be more helpful. Change-Id: I711b6a193a4ad94b5ff714c025f2732cd1a965a7 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-xutil/local_database/cldr2qlocalexml.py170
-rw-r--r--util/local_database/localexml.py233
-rwxr-xr-xutil/local_database/qlocalexml2cpp.py101
3 files changed, 255 insertions, 249 deletions
diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py
index 3b4243ea85..0e61af5610 100755
--- a/util/local_database/cldr2qlocalexml.py
+++ b/util/local_database/cldr2qlocalexml.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#############################################################################
##
-## Copyright (C) 2016 The Qt Company Ltd.
+## Copyright (C) 2017 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of the test suite of the Qt Toolkit.
@@ -42,12 +42,13 @@ file for later processing by ``./qlocalexml2cpp.py``
import os
import sys
+import re
+
import enumdata
import xpathlite
from xpathlite import DraftResolution
from dateconverter import convert_date
-from xml.sax.saxutils import escape, unescape
-import re
+from localexml import Locale
findAlias = xpathlite.findAlias
findEntry = xpathlite.findEntry
@@ -92,36 +93,6 @@ def parse_list_pattern_part_format(pattern):
result = result.replace("{2}", "%3")
return result
-def ordStr(c):
- if len(c) == 1:
- return str(ord(c))
- raise xpathlite.Error('Unable to handle value "%s"' % addEscapes(c))
- return "##########"
-
-# the following functions are supposed to fix the problem with QLocale
-# returning a character instead of strings for QLocale::exponential()
-# and others. So we fallback to default values in these cases.
-def fixOrdStrMinus(c):
- if len(c) == 1:
- return str(ord(c))
- return str(ord('-'))
-def fixOrdStrPlus(c):
- if len(c) == 1:
- return str(ord(c))
- return str(ord('+'))
-def fixOrdStrExp(c):
- if len(c) == 1:
- return str(ord(c))
- return str(ord('e'))
-def fixOrdStrPercent(c):
- if len(c) == 1:
- return str(ord(c))
- return str(ord('%'))
-def fixOrdStrList(c):
- if len(c) == 1:
- return str(ord(c))
- return str(ord(';'))
-
def generateLocaleInfo(path):
if not path.endswith(".xml"):
return {}
@@ -327,7 +298,7 @@ def _generateLocaleInfo(path, language_code, script_code, country_code, variant_
findEntry(path, stem + prop + '[' + day + ']')
for day in days) + ';'
- return result
+ return Locale(result)
def addEscapes(s):
result = ''
@@ -423,22 +394,22 @@ def integrateWeekData(filePath):
for countryCode in sunWeekendEnd:
weekendEndByCountryCode[countryCode] = "sun"
- for (key,locale) in locale_database.iteritems():
- countryCode = locale['country_code']
+ for (key, locale) in locale_database.iteritems():
+ countryCode = locale.country_code
if countryCode in firstDayByCountryCode:
- locale_database[key]['firstDayOfWeek'] = firstDayByCountryCode[countryCode]
+ locale.firstDayOfWeek = firstDayByCountryCode[countryCode]
else:
- locale_database[key]['firstDayOfWeek'] = firstDayByCountryCode["001"]
+ locale.firstDayOfWeek = firstDayByCountryCode["001"]
if countryCode in weekendStartByCountryCode:
- locale_database[key]['weekendStart'] = weekendStartByCountryCode[countryCode]
+ locale.weekendStart = weekendStartByCountryCode[countryCode]
else:
- locale_database[key]['weekendStart'] = weekendStartByCountryCode["001"]
+ locale.weekendStart = weekendStartByCountryCode["001"]
if countryCode in weekendEndByCountryCode:
- locale_database[key]['weekendEnd'] = weekendEndByCountryCode[countryCode]
+ locale.weekendEnd = weekendEndByCountryCode[countryCode]
else:
- locale_database[key]['weekendEnd'] = weekendEndByCountryCode["001"]
+ locale.weekendEnd = weekendEndByCountryCode["001"]
if len(sys.argv) != 2:
usage()
@@ -484,7 +455,7 @@ for file in defaultContent_locales:
sys.stderr.write('skipping defaultContent locale "%s" (%s)\n' % (file, str(e)))
continue
- locale_database[(l['language_id'], l['script_id'], l['country_id'], l['variant_code'])] = l
+ locale_database[(l.language_id, l.script_id, l.country_id, l.variant_code)] = l
for file in cldr_files:
try:
@@ -496,7 +467,7 @@ for file in cldr_files:
sys.stderr.write('skipping file "%s" (%s)\n' % (file, str(e)))
continue
- locale_database[(l['language_id'], l['script_id'], l['country_id'], l['variant_code'])] = l
+ locale_database[(l.language_id, l.script_id, l.country_id, l.variant_code)] = l
integrateWeekData(cldr_dir+"/../supplemental/supplementalData.xml")
locale_keys = locale_database.keys()
@@ -613,115 +584,10 @@ for ns in findTagsInFile(cldr_dir + "/../supplemental/likelySubtags.xml", "likel
print " </likelySubtags>"
print " <localeList>"
-print '''\
- <locale>
- <language>C</language>
- <languageEndonym></languageEndonym>
- <script>AnyScript</script>
- <country>AnyCountry</country>
- <countryEndonym></countryEndonym>
- <decimal>46</decimal>
- <group>44</group>
- <list>59</list>
- <percent>37</percent>
- <zero>48</zero>
- <minus>45</minus>
- <plus>43</plus>
- <exp>101</exp>
- <quotationStart>"</quotationStart>
- <quotationEnd>"</quotationEnd>
- <alternateQuotationStart>\'</alternateQuotationStart>
- <alternateQuotationEnd>\'</alternateQuotationEnd>
- <listPatternPartStart>%1, %2</listPatternPartStart>
- <listPatternPartMiddle>%1, %2</listPatternPartMiddle>
- <listPatternPartEnd>%1, %2</listPatternPartEnd>
- <listPatternPartTwo>%1, %2</listPatternPartTwo>
- <am>AM</am>
- <pm>PM</pm>
- <firstDayOfWeek>mon</firstDayOfWeek>
- <weekendStart>sat</weekendStart>
- <weekendEnd>sun</weekendEnd>
- <longDateFormat>EEEE, d MMMM yyyy</longDateFormat>
- <shortDateFormat>d MMM yyyy</shortDateFormat>
- <longTimeFormat>HH:mm:ss z</longTimeFormat>
- <shortTimeFormat>HH:mm:ss</shortTimeFormat>
- <standaloneLongMonths>January;February;March;April;May;June;July;August;September;October;November;December;</standaloneLongMonths>
- <standaloneShortMonths>Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec;</standaloneShortMonths>
- <standaloneNarrowMonths>J;F;M;A;M;J;J;A;S;O;N;D;</standaloneNarrowMonths>
- <longMonths>January;February;March;April;May;June;July;August;September;October;November;December;</longMonths>
- <shortMonths>Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec;</shortMonths>
- <narrowMonths>1;2;3;4;5;6;7;8;9;10;11;12;</narrowMonths>
- <longDays>Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday;</longDays>
- <shortDays>Sun;Mon;Tue;Wed;Thu;Fri;Sat;</shortDays>
- <narrowDays>7;1;2;3;4;5;6;</narrowDays>
- <standaloneLongDays>Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday;</standaloneLongDays>
- <standaloneShortDays>Sun;Mon;Tue;Wed;Thu;Fri;Sat;</standaloneShortDays>
- <standaloneNarrowDays>S;M;T;W;T;F;S;</standaloneNarrowDays>
- <currencyIsoCode></currencyIsoCode>
- <currencySymbol></currencySymbol>
- <currencyDisplayName>;;;;;;;</currencyDisplayName>
- <currencyDigits>2</currencyDigits>
- <currencyRounding>1</currencyRounding>
- <currencyFormat>%1%2</currencyFormat>
- <currencyNegativeFormat></currencyNegativeFormat>
- </locale>'''
+Locale.C().toXml()
for key in locale_keys:
- l = locale_database[key]
-
- print " <locale>"
- print " <language>" + l['language'] + "</language>"
- print " <languageEndonym>" + escape(l['language_endonym']).encode('utf-8') + "</languageEndonym>"
- print " <script>" + l['script'] + "</script>"
- print " <country>" + l['country'] + "</country>"
- print " <countryEndonym>" + escape(l['country_endonym']).encode('utf-8') + "</countryEndonym>"
- print " <languagecode>" + l['language_code'] + "</languagecode>"
- print " <scriptcode>" + l['script_code'] + "</scriptcode>"
- print " <countrycode>" + l['country_code'] + "</countrycode>"
- print " <decimal>" + ordStr(l['decimal']) + "</decimal>"
- print " <group>" + ordStr(l['group']) + "</group>"
- print " <list>" + fixOrdStrList(l['list']) + "</list>"
- print " <percent>" + fixOrdStrPercent(l['percent']) + "</percent>"
- print " <zero>" + ordStr(l['zero']) + "</zero>"
- print " <minus>" + fixOrdStrMinus(l['minus']) + "</minus>"
- print " <plus>" + fixOrdStrPlus(l['plus']) + "</plus>"
- print " <exp>" + fixOrdStrExp(l['exp']) + "</exp>"
- print " <quotationStart>" + escape(l['quotationStart']).encode('utf-8') + "</quotationStart>"
- print " <quotationEnd>" + escape(l['quotationEnd']).encode('utf-8') + "</quotationEnd>"
- print " <alternateQuotationStart>" + escape(l['alternateQuotationStart']).encode('utf-8') + "</alternateQuotationStart>"
- print " <alternateQuotationEnd>" + escape(l['alternateQuotationEnd']).encode('utf-8') + "</alternateQuotationEnd>"
- print " <listPatternPartStart>" + escape(l['listPatternPartStart']).encode('utf-8') + "</listPatternPartStart>"
- print " <listPatternPartMiddle>" + escape(l['listPatternPartMiddle']).encode('utf-8') + "</listPatternPartMiddle>"
- print " <listPatternPartEnd>" + escape(l['listPatternPartEnd']).encode('utf-8') + "</listPatternPartEnd>"
- print " <listPatternPartTwo>" + escape(l['listPatternPartTwo']).encode('utf-8') + "</listPatternPartTwo>"
- print " <am>" + escape(l['am']).encode('utf-8') + "</am>"
- print " <pm>" + escape(l['pm']).encode('utf-8') + "</pm>"
- print " <firstDayOfWeek>" + escape(l['firstDayOfWeek']).encode('utf-8') + "</firstDayOfWeek>"
- print " <weekendStart>" + escape(l['weekendStart']).encode('utf-8') + "</weekendStart>"
- print " <weekendEnd>" + escape(l['weekendEnd']).encode('utf-8') + "</weekendEnd>"
- print " <longDateFormat>" + escape(l['longDateFormat']).encode('utf-8') + "</longDateFormat>"
- print " <shortDateFormat>" + escape(l['shortDateFormat']).encode('utf-8') + "</shortDateFormat>"
- print " <longTimeFormat>" + escape(l['longTimeFormat']).encode('utf-8') + "</longTimeFormat>"
- print " <shortTimeFormat>" + escape(l['shortTimeFormat']).encode('utf-8') + "</shortTimeFormat>"
- print " <standaloneLongMonths>" + escape(l['standaloneLongMonths']).encode('utf-8') + "</standaloneLongMonths>"
- print " <standaloneShortMonths>"+ escape(l['standaloneShortMonths']).encode('utf-8') + "</standaloneShortMonths>"
- print " <standaloneNarrowMonths>"+ escape(l['standaloneNarrowMonths']).encode('utf-8') + "</standaloneNarrowMonths>"
- print " <longMonths>" + escape(l['longMonths']).encode('utf-8') + "</longMonths>"
- print " <shortMonths>" + escape(l['shortMonths']).encode('utf-8') + "</shortMonths>"
- print " <narrowMonths>" + escape(l['narrowMonths']).encode('utf-8') + "</narrowMonths>"
- print " <longDays>" + escape(l['longDays']).encode('utf-8') + "</longDays>"
- print " <shortDays>" + escape(l['shortDays']).encode('utf-8') + "</shortDays>"
- print " <narrowDays>" + escape(l['narrowDays']).encode('utf-8') + "</narrowDays>"
- print " <standaloneLongDays>" + escape(l['standaloneLongDays']).encode('utf-8') + "</standaloneLongDays>"
- print " <standaloneShortDays>" + escape(l['standaloneShortDays']).encode('utf-8') + "</standaloneShortDays>"
- print " <standaloneNarrowDays>" + escape(l['standaloneNarrowDays']).encode('utf-8') + "</standaloneNarrowDays>"
- print " <currencyIsoCode>" + escape(l['currencyIsoCode']).encode('utf-8') + "</currencyIsoCode>"
- print " <currencySymbol>" + escape(l['currencySymbol']).encode('utf-8') + "</currencySymbol>"
- print " <currencyDisplayName>" + escape(l['currencyDisplayName']).encode('utf-8') + "</currencyDisplayName>"
- print " <currencyDigits>" + str(l['currencyDigits']) + "</currencyDigits>"
- print " <currencyRounding>" + str(l['currencyRounding']) + "</currencyRounding>"
- print " <currencyFormat>" + escape(l['currencyFormat']).encode('utf-8') + "</currencyFormat>"
- print " <currencyNegativeFormat>" + escape(l['currencyNegativeFormat']).encode('utf-8') + "</currencyNegativeFormat>"
- print " </locale>"
+ locale_database[key].toXml()
+
print " </localeList>"
print "</localeDatabase>"
diff --git a/util/local_database/localexml.py b/util/local_database/localexml.py
new file mode 100644
index 0000000000..6db10e2b9a
--- /dev/null
+++ b/util/local_database/localexml.py
@@ -0,0 +1,233 @@
+#############################################################################
+##
+## Copyright (C) 2017 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of the Qt Toolkit.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+"""Shared serialization-scanning code for QLocaleXML format.
+
+The Locale class is written by cldr2qlocalexml.py and read by qlocalexml2cpp.py
+"""
+from xml.sax.saxutils import escape
+
+import xpathlite
+
+# Tools used by Locale:
+def camel(seq):
+ yield seq.next()
+ for word in seq:
+ yield word.capitalize()
+
+def camelCase(words):
+ return ''.join(camel(iter(words)))
+
+def ordStr(c):
+ if len(c) == 1:
+ return str(ord(c))
+ raise xpathlite.Error('Unable to handle value "%s"' % addEscapes(c))
+
+# Fix for a problem with QLocale returning a character instead of
+# strings for QLocale::exponential() and others. So we fallback to
+# default values in these cases.
+def fixOrdStr(c, d):
+ return str(ord(c if len(c) == 1 else d))
+
+def convertFormat(format):
+ result = ""
+ i = 0
+ while i < len(format):
+ if format[i] == "'":
+ result += "'"
+ i += 1
+ while i < len(format) and format[i] != "'":
+ result += format[i]
+ i += 1
+ if i < len(format):
+ result += "'"
+ i += 1
+ else:
+ s = format[i:]
+ if s.startswith("EEEE"):
+ result += "dddd"
+ i += 4
+ elif s.startswith("EEE"):
+ result += "ddd"
+ i += 3
+ elif s.startswith("a"):
+ result += "AP"
+ i += 1
+ elif s.startswith("z"):
+ result += "t"
+ i += 1
+ elif s.startswith("v"):
+ i += 1
+ else:
+ result += format[i]
+ i += 1
+
+ return result
+
+class Locale:
+ # Tool used during class body (see del below), not method:
+ def propsMonthDay(lengths=('long', 'short', 'narrow'), scale=('months', 'days')):
+ for L in lengths:
+ for S in scale:
+ yield camelCase((L, S))
+ yield camelCase(('standalone', L, S))
+
+ # Expected to be numbers, read with int():
+ __asint = ("decimal", "group", "zero",
+ "list", "percent", "minus", "plus", "exp",
+ "currencyDigits", "currencyRounding")
+ # Single character; use the code-point number for each:
+ __asord = ("quotationStart", "quotationEnd",
+ "alternateQuotationStart", "alternateQuotationEnd")
+ # Convert day-name to Qt day-of-week number:
+ __asdow = ("firstDayOfWeek", "weekendStart", "weekendEnd")
+ # Convert from CLDR format-strings to QDateTimeParser ones:
+ __asfmt = ("longDateFormat", "shortDateFormat", "longTimeFormat", "shortTimeFormat")
+ # Just use the raw text:
+ __astxt = ("language", "languageEndonym", "script", "country", "countryEndonym",
+ "listPatternPartStart", "listPatternPartMiddle",
+ "listPatternPartEnd", "listPatternPartTwo", "am", "pm",
+ "currencyIsoCode", "currencySymbol", "currencyDisplayName",
+ "currencyFormat", "currencyNegativeFormat"
+ ) + tuple(propsMonthDay())
+ del propsMonthDay
+
+ # Day-of-Week numbering used by Qt:
+ __qDoW = {"mon": 1, "tue": 2, "wed": 3, "thu": 4, "fri": 5, "sat": 6, "sun": 7}
+
+ @classmethod
+ def fromXmlData(cls, lookup):
+ """Constructor from the contents of XML elements.
+
+ Single parameter, lookup, is called with the names of XML
+ elements that should contain the relevant data, within a CLDR
+ locale element (within a localeList element); these names are
+ used for the attributes of the object constructed. Attribute
+ values are obtained by suitably digesting the returned element
+ texts.\n"""
+ data = {}
+ for k in cls.__asint:
+ data['listDelim' if k == 'list' else k] = int(lookup(k))
+
+ for k in cls.__asord:
+ value = lookup(k)
+ assert len(value) == 1, \
+ (k, value, 'value should be exactly one character')
+ data[k] = ord(value)
+
+ for k in cls.__asdow:
+ data[k] = cls.__qDoW[lookup(k)]
+
+ for k in cls.__asfmt:
+ data[k] = convertFormat(lookup(k))
+
+ for k in cls.__astxt:
+ data[k] = lookup(k)
+
+ return cls(data)
+
+ def toXml(self, indent=' ', tab=' '):
+ print indent + '<locale>'
+ inner = indent + tab
+ get = lambda k: getattr(self, k)
+ for key in ('language', 'script', 'country'):
+ print inner + "<%s>" % key + get(key) + "</%s>" % key
+ print inner + "<%scode>" % key + get(key + '_code') + "</%scode>" % key
+
+ for key in ('decimal', 'group', 'zero'):
+ print inner + "<%s>" % key + ordStr(get(key)) + "</%s>" % key
+ for key, std in (('list', ';'), ('percent', '%'),
+ ('minus', '-'), ('plus', '+'), ('exp', 'e')):
+ print inner + "<%s>" % key + fixOrdStr(get(key), std) + "</%s>" % key
+
+ for key in ('language_endonym', 'country_endonym',
+ 'quotationStart', 'quotationEnd',
+ 'alternateQuotationStart', 'alternateQuotationEnd',
+ 'listPatternPartStart', 'listPatternPartMiddle',
+ 'listPatternPartEnd', 'listPatternPartTwo',
+ 'am', 'pm', 'firstDayOfWeek',
+ 'weekendStart', 'weekendEnd',
+ 'longDateFormat', 'shortDateFormat',
+ 'longTimeFormat', 'shortTimeFormat',
+ 'standaloneLongMonths', 'standaloneShortMonths',
+ 'standaloneNarrowMonths',
+ 'longMonths', 'shortMonths', 'narrowMonths',
+ 'longDays', 'shortDays', 'narrowDays',
+ 'standaloneLongDays', 'standaloneShortDays', 'standaloneNarrowDays',
+ 'currencyIsoCode', 'currencySymbol', 'currencyDisplayName',
+ 'currencyFormat', 'currencyNegativeFormat'):
+ ent = camelCase(key.split('_')) if '_' in key else key
+ print inner + "<%s>%s</%s>" % (ent, escape(get(key)).encode('utf-8'), ent)
+
+ for key in ('currencyDigits', 'currencyRounding'):
+ print inner + "<%s>%d</%s>" % (key, get(key), key)
+
+ print indent + "</locale>"
+
+ def __init__(self, data=None, **kw):
+ if data: self.__dict__.update(data)
+ if kw: self.__dict__.update(kw)
+
+ @classmethod
+ def C(cls,
+ # Empty entries at end to ensure final separator when join()ed:
+ months = ('January', 'February', 'March', 'April', 'May', 'June', 'July',
+ 'August', 'September', 'October', 'November', 'December', ''),
+ days = ('Sunday', 'Monday', 'Tuesday', 'Wednesday',
+ 'Thursday', 'Friday', 'Saturday', '')):
+ """Returns an object representing the C locale."""
+ return cls(language='C', language_code='0', language_endonym='',
+ script='AnyScript', script_code='0',
+ country='AnyCountry', country_code='0', country_endonym='',
+ decimal='.', group=',', list=';', percent='%',
+ zero='0', minus='-', plus='+', exp='e',
+ quotationStart='"', quotationEnd='"',
+ alternateQuotationStart='\'', alternateQuotationEnd='\'',
+ listPatternPartStart='%1, %2',
+ listPatternPartMiddle='%1, %2',
+ listPatternPartEnd='%1, %2',
+ listPatternPartTwo='%1, %2',
+ am='AM', pm='PM', firstDayOfWeek='mon',
+ weekendStart='sat', weekendEnd='sun',
+ longDateFormat='EEEE, d MMMM yyyy', shortDateFormat='d MMM yyyy',
+ longTimeFormat='HH:mm:ss z', shortTimeFormat='HH:mm:ss',
+ longMonths=';'.join(months),
+ shortMonths=';'.join(m[:3] for m in months),
+ narrowMonths='1;2;3;4;5;6;7;8;9;10;11;12;',
+ standaloneLongMonths=';'.join(months),
+ standaloneShortMonths=';'.join(m[:3] for m in months),
+ standaloneNarrowMonths=';'.join(m[:1] for m in months),
+ longDays=';'.join(days),
+ shortDays=';'.join(d[:3] for d in days),
+ narrowDays='7;1;2;3;4;5;6;',
+ standaloneLongDays=';'.join(days),
+ standaloneShortDays=';'.join(d[:3] for d in days),
+ standaloneNarrowDays=';'.join(d[:1] for d in days),
+ currencyIsoCode='', currencySymbol='',
+ currencyDisplayName=';' * 7,
+ currencyDigits=2, currencyRounding=1,
+ currencyFormat='%1%2', currencyNegativeFormat='')
diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py
index d132027294..d2517aaa48 100755
--- a/util/local_database/qlocalexml2cpp.py
+++ b/util/local_database/qlocalexml2cpp.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
#############################################################################
##
-## Copyright (C) 2016 The Qt Company Ltd.
+## Copyright (C) 2017 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of the test suite of the Qt Toolkit.
@@ -39,6 +39,8 @@ import tempfile
import datetime
import xml.dom.minidom
+from localexml import Locale
+
class Error:
def __init__(self, msg):
self.msg = msg
@@ -191,108 +193,13 @@ def countryNameToId(name, country_map):
return key
return -1
-def convertFormat(format):
- result = ""
- i = 0
- while i < len(format):
- if format[i] == "'":
- result += "'"
- i += 1
- while i < len(format) and format[i] != "'":
- result += format[i]
- i += 1
- if i < len(format):
- result += "'"
- i += 1
- else:
- s = format[i:]
- if s.startswith("EEEE"):
- result += "dddd"
- i += 4
- elif s.startswith("EEE"):
- result += "ddd"
- i += 3
- elif s.startswith("a"):
- result += "AP"
- i += 1
- elif s.startswith("z"):
- result += "t"
- i += 1
- elif s.startswith("v"):
- i += 1
- else:
- result += format[i]
- i += 1
-
- return result
-
-def convertToQtDayOfWeek(firstDay):
- qtDayOfWeek = {"mon":1, "tue":2, "wed":3, "thu":4, "fri":5, "sat":6, "sun":7}
- return qtDayOfWeek[firstDay]
-
-def assertSingleChar(string):
- assert len(string) == 1, "This string is not allowed to be longer than 1 character"
- return string
-
-class Locale:
- def __init__(self, elt):
- self.language = eltText(firstChildElt(elt, "language"))
- self.languageEndonym = eltText(firstChildElt(elt, "languageEndonym"))
- self.script = eltText(firstChildElt(elt, "script"))
- self.country = eltText(firstChildElt(elt, "country"))
- self.countryEndonym = eltText(firstChildElt(elt, "countryEndonym"))
- self.decimal = int(eltText(firstChildElt(elt, "decimal")))
- self.group = int(eltText(firstChildElt(elt, "group")))
- self.listDelim = int(eltText(firstChildElt(elt, "list")))
- self.percent = int(eltText(firstChildElt(elt, "percent")))
- self.zero = int(eltText(firstChildElt(elt, "zero")))
- self.minus = int(eltText(firstChildElt(elt, "minus")))
- self.plus = int(eltText(firstChildElt(elt, "plus")))
- self.exp = int(eltText(firstChildElt(elt, "exp")))
- self.quotationStart = ord(assertSingleChar(eltText(firstChildElt(elt, "quotationStart"))))
- self.quotationEnd = ord(assertSingleChar(eltText(firstChildElt(elt, "quotationEnd"))))
- self.alternateQuotationStart = ord(assertSingleChar(eltText(firstChildElt(elt, "alternateQuotationStart"))))
- self.alternateQuotationEnd = ord(assertSingleChar(eltText(firstChildElt(elt, "alternateQuotationEnd"))))
- self.listPatternPartStart = eltText(firstChildElt(elt, "listPatternPartStart"))
- self.listPatternPartMiddle = eltText(firstChildElt(elt, "listPatternPartMiddle"))
- self.listPatternPartEnd = eltText(firstChildElt(elt, "listPatternPartEnd"))
- self.listPatternPartTwo = eltText(firstChildElt(elt, "listPatternPartTwo"))
- self.am = eltText(firstChildElt(elt, "am"))
- self.pm = eltText(firstChildElt(elt, "pm"))
- self.firstDayOfWeek = convertToQtDayOfWeek(eltText(firstChildElt(elt, "firstDayOfWeek")))
- self.weekendStart = convertToQtDayOfWeek(eltText(firstChildElt(elt, "weekendStart")))
- self.weekendEnd = convertToQtDayOfWeek(eltText(firstChildElt(elt, "weekendEnd")))
- self.longDateFormat = convertFormat(eltText(firstChildElt(elt, "longDateFormat")))
- self.shortDateFormat = convertFormat(eltText(firstChildElt(elt, "shortDateFormat")))
- self.longTimeFormat = convertFormat(eltText(firstChildElt(elt, "longTimeFormat")))
- self.shortTimeFormat = convertFormat(eltText(firstChildElt(elt, "shortTimeFormat")))
- self.standaloneLongMonths = eltText(firstChildElt(elt, "standaloneLongMonths"))
- self.standaloneShortMonths = eltText(firstChildElt(elt, "standaloneShortMonths"))
- self.standaloneNarrowMonths = eltText(firstChildElt(elt, "standaloneNarrowMonths"))
- self.longMonths = eltText(firstChildElt(elt, "longMonths"))
- self.shortMonths = eltText(firstChildElt(elt, "shortMonths"))
- self.narrowMonths = eltText(firstChildElt(elt, "narrowMonths"))
- self.standaloneLongDays = eltText(firstChildElt(elt, "standaloneLongDays"))
- self.standaloneShortDays = eltText(firstChildElt(elt, "standaloneShortDays"))
- self.standaloneNarrowDays = eltText(firstChildElt(elt, "standaloneNarrowDays"))
- self.longDays = eltText(firstChildElt(elt, "longDays"))
- self.shortDays = eltText(firstChildElt(elt, "shortDays"))
- self.narrowDays = eltText(firstChildElt(elt, "narrowDays"))
- self.currencyIsoCode = eltText(firstChildElt(elt, "currencyIsoCode"))
- self.currencySymbol = eltText(firstChildElt(elt, "currencySymbol"))
- self.currencyDisplayName = eltText(firstChildElt(elt, "currencyDisplayName"))
- self.currencyDigits = int(eltText(firstChildElt(elt, "currencyDigits")))
- self.currencyRounding = int(eltText(firstChildElt(elt, "currencyRounding")))
- self.currencyFormat = eltText(firstChildElt(elt, "currencyFormat"))
- self.currencyNegativeFormat = eltText(firstChildElt(elt, "currencyNegativeFormat"))
-
def loadLocaleMap(doc, language_map, script_map, country_map, likely_subtags_map):
result = {}
locale_list_elt = firstChildElt(doc.documentElement, "localeList")
locale_elt = firstChildElt(locale_list_elt, "locale")
while locale_elt:
- locale = Locale(locale_elt)
+ locale = Locale.fromXmlData(lambda k: eltText(firstChildElt(locale_elt, k)))
language_id = languageNameToId(locale.language, language_map)
if language_id == -1:
sys.stderr.write("Cannot find a language id for '%s'\n" % locale.language)