From 049cc0e6717f684453d40f78e9ec0e9093df2c1d Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Tue, 15 Feb 2011 13:50:20 +0100 Subject: Implemented QLocale::firstDayOfWeek() REMARK: This commit is missing updated static cldr data in src/corelib/tools/qlocale_data_p.h that has been left out intentionally to avoid repository bloating. Before compiling make sure to update that file using the scripts util/local_database/cldr2qlocalexml.py and util/local_database/qlocalexml2cpp.py. Otherwise you will most likely experience segmentation faults. Reviewed-By: Denis Dzyubenko --- util/local_database/cldr2qlocalexml.py | 37 ++++++++++++++++++++++++++++++++++ util/local_database/qlocalexml2cpp.py | 10 +++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index 2567a89c84..8b5ec16106 100755 --- a/util/local_database/cldr2qlocalexml.py +++ b/util/local_database/cldr2qlocalexml.py @@ -322,6 +322,40 @@ def usage(): print "Usage: cldr2qlocalexml.py " sys.exit() +def integrateWeekData(filePath): + if not filePath.endswith(".xml"): + return {} + monFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=mon]", attribute="territories")[0].split(" ") + tueFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=tue]", attribute="territories")[0].split(" ") + wedFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=wed]", attribute="territories")[0].split(" ") + thuFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=thu]", attribute="territories")[0].split(" ") + friFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=fri]", attribute="territories")[0].split(" ") + satFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=sat]", attribute="territories")[0].split(" ") + sunFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=sun]", attribute="territories")[0].split(" ") + + firstDayByCountryCode = {} + for countryCode in monFirstDayIn: + firstDayByCountryCode[countryCode] = "mon" + for countryCode in tueFirstDayIn: + firstDayByCountryCode[countryCode] = "tue" + for countryCode in wedFirstDayIn: + firstDayByCountryCode[countryCode] = "wed" + for countryCode in thuFirstDayIn: + firstDayByCountryCode[countryCode] = "thu" + for countryCode in friFirstDayIn: + firstDayByCountryCode[countryCode] = "fri" + for countryCode in satFirstDayIn: + firstDayByCountryCode[countryCode] = "sat" + for countryCode in sunFirstDayIn: + firstDayByCountryCode[countryCode] = "sun" + + for (key,locale) in locale_database.iteritems(): + countryCode = locale['country_code'] + if countryCode in firstDayByCountryCode: + locale_database[key]['firstDayOfWeek'] = firstDayByCountryCode[countryCode] + else: + locale_database[key]['firstDayOfWeek'] = firstDayByCountryCode["001"] + if len(sys.argv) != 2: usage() @@ -341,6 +375,7 @@ for file in cldr_files: locale_database[(l['language_id'], l['country_id'], l['script_code'], l['variant_code'])] = l +integrateWeekData(cldr_dir+"/../supplemental/supplementalData.xml") locale_keys = locale_database.keys() locale_keys.sort() @@ -484,6 +519,7 @@ print \ 101\n\ AM\n\ PM\n\ + mon\n\ EEEE, d MMMM yyyy\n\ d MMM yyyy\n\ HH:mm:ss z\n\ @@ -520,6 +556,7 @@ for key in locale_keys: print " " + fixOrdStrExp(l['exp']) + "" print " " + l['am'].encode('utf-8') + "" print " " + l['pm'].encode('utf-8') + "" + print " " + l['firstDayOfWeek'].encode('utf-8') + "" print " " + l['longDateFormat'].encode('utf-8') + "" print " " + l['shortDateFormat'].encode('utf-8') + "" print " " + l['longTimeFormat'].encode('utf-8') + "" diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index 9251e1f77f..9bc3c7e6c7 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -188,6 +188,10 @@ def convertFormat(format): return result +def convertToQtDayOfWeek(firstDay): + qtDayOfWeek = {"mon":1, "tue":2, "wed":3, "thu":4, "fri":5, "sat":6, "sun":7} + return qtDayOfWeek[firstDay] + class Locale: def __init__(self, elt): self.language = eltText(firstChildElt(elt, "language")) @@ -202,6 +206,7 @@ class Locale: self.exp = int(eltText(firstChildElt(elt, "exp"))) self.am = eltText(firstChildElt(elt, "am")) self.pm = eltText(firstChildElt(elt, "pm")) + self.firstDayOfWeek = convertToQtDayOfWeek(eltText(firstChildElt(elt, "firstDayOfWeek"))) self.longDateFormat = convertFormat(eltText(firstChildElt(elt, "longDateFormat"))) self.shortDateFormat = convertFormat(eltText(firstChildElt(elt, "shortDateFormat"))) self.longTimeFormat = convertFormat(eltText(firstChildElt(elt, "longTimeFormat"))) @@ -397,7 +402,7 @@ def main(): for key in locale_keys: l = locale_map[key] - print " { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s }, // %s/%s" \ + print " { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%6d }, // %s/%s" \ % (key[0], key[1], l.decimal, l.group, @@ -425,9 +430,10 @@ def main(): days_data.append(l.narrowDays), am_data.append(l.am), pm_data.append(l.pm), + l.firstDayOfWeek, l.language, l.country) - print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 } // trailing 0s" + print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0 } // trailing 0s" print "};" print -- cgit v1.2.1 From 2f880e66c2dedc8b072dca4672035fc5b2e659bc Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Tue, 8 Feb 2011 19:53:55 +0100 Subject: Added currency support for QLocale REMARK: This commit is missing updated static cldr data in src/corelib/tools/qlocale_data_p.h that has been left out intentionally to avoid repository bloating. Before compiling make sure to update that file using the scripts util/local_database/cldr2qlocalexml.py and util/local_database/qlocalexml2cpp.py. Otherwise you will most likely experience segmentation faults. Task-number: QTBUG-17100 Reviewed-by: Zeno Albisser --- util/local_database/cldr2qlocalexml.py | 92 +++++++++++++++++++++++++++++++++- util/local_database/qlocalexml2cpp.py | 49 +++++++++++++++++- util/local_database/xpathlite.py | 42 ++++++++++++++++ 3 files changed, 180 insertions(+), 3 deletions(-) (limited to 'util') diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index 8b5ec16106..311cf4e02e 100755 --- a/util/local_database/cldr2qlocalexml.py +++ b/util/local_database/cldr2qlocalexml.py @@ -50,6 +50,37 @@ import re findEntry = xpathlite.findEntry findEntryInFile = xpathlite._findEntryInFile +findTagsInFile = xpathlite.findTagsInFile + +def parse_number_format(patterns, data): + # this is a very limited parsing of the number format for currency only. + def skip_repeating_pattern(x): + p = x.replace('0', '#').replace(',', '').replace('.', '') + seen = False + result = '' + for c in p: + if c == '#': + if seen: + continue + seen = True + else: + seen = False + result = result + c + return result + patterns = patterns.split(';') + result = [] + for pattern in patterns: + pattern = skip_repeating_pattern(pattern) + pattern = pattern.replace('#', "%1") + # according to http://www.unicode.org/reports/tr35/#Number_Format_Patterns + # there can be doubled or trippled currency sign, however none of the + # locales use that. + pattern = pattern.replace(u'\xa4', "%2") + pattern = pattern.replace("''", "###").replace("'", '').replace("###", "'") + pattern = pattern.replace('-', data['minus']) + pattern = pattern.replace('+', data['plus']) + result.append(pattern) + return result def ordStr(c): if len(c) == 1: @@ -123,11 +154,36 @@ def generateLocaleInfo(path): result['language_id'] = language_id result['country_id'] = country_id + supplementalPath = dir_name + "/../supplemental/supplementalData.xml" + currencies = findTagsInFile(supplementalPath, "currencyData/region[iso3166=%s]"%country_code); + result['currencyIsoCode'] = '' + result['currencyDigits'] = 2 + result['currencyRounding'] = 1 + if currencies: + for e in currencies: + if e[0] == 'currency': + tender = True + t = filter(lambda x: x[0] == 'tender', e[1]) + if t and t[0][1] == 'false': + tender = False; + if tender and not filter(lambda x: x[0] == 'to', e[1]): + result['currencyIsoCode'] = filter(lambda x: x[0] == 'iso4217', e[1])[0][1] + break + if result['currencyIsoCode']: + t = findTagsInFile(supplementalPath, "currencyData/fractions/info[iso4217=%s]"%result['currencyIsoCode']); + if t and t[0][0] == 'info': + result['currencyDigits'] = int(filter(lambda x: x[0] == 'digits', t[0][1])[0][1]) + result['currencyRounding'] = int(filter(lambda x: x[0] == 'rounding', t[0][1])[0][1]) numbering_system = None try: numbering_system = findEntry(path, "numbers/defaultNumberingSystem") except: pass + def findEntryDef(path, xpath, value=''): + try: + return findEntry(path, xpath) + except xpathlite.Error: + return value def get_number_in_system(path, xpath, numbering_system): if numbering_system: try: @@ -150,6 +206,27 @@ def generateLocaleInfo(path): result['longTimeFormat'] = convert_date(findEntry(path, "dates/calendars/calendar[gregorian]/timeFormats/timeFormatLength[full]/timeFormat/pattern")) result['shortTimeFormat'] = convert_date(findEntry(path, "dates/calendars/calendar[gregorian]/timeFormats/timeFormatLength[short]/timeFormat/pattern")) + currency_format = get_number_in_system(path, "numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern", numbering_system) + currency_format = parse_number_format(currency_format, result) + result['currencyFormat'] = currency_format[0] + result['currencyNegativeFormat'] = '' + if len(currency_format) > 1: + result['currencyNegativeFormat'] = currency_format[1] + + result['currencySymbol'] = '' + result['currencyDisplayName'] = '' + if result['currencyIsoCode']: + result['currencySymbol'] = findEntryDef(path, "numbers/currencies/currency[%s]/symbol" % result['currencyIsoCode']) + display_name_path = "numbers/currencies/currency[%s]/displayName" % result['currencyIsoCode'] + result['currencyDisplayName'] \ + = findEntryDef(path, display_name_path) + ";" \ + + findEntryDef(path, display_name_path + "[count=zero]") + ";" \ + + findEntryDef(path, display_name_path + "[count=one]") + ";" \ + + findEntryDef(path, display_name_path + "[count=two]") + ";" \ + + findEntryDef(path, display_name_path + "[count=few]") + ";" \ + + findEntryDef(path, display_name_path + "[count=many]") + ";" \ + + findEntryDef(path, display_name_path + "[count=other]") + ";" + standalone_long_month_path = "dates/calendars/calendar[gregorian]/months/monthContext[stand-alone]/monthWidth[wide]/month" result['standaloneLongMonths'] \ = findEntry(path, standalone_long_month_path + "[1]") + ";" \ @@ -300,7 +377,6 @@ def generateLocaleInfo(path): + findEntry(path, standalone_narrow_day_path + "[fri]") + ";" \ + findEntry(path, standalone_narrow_day_path + "[sat]") + ";" - return result def addEscapes(s): @@ -536,6 +612,13 @@ print \ Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday;\n\ Sun;Mon;Tue;Wed;Thu;Fri;Sat;\n\ S;M;T;W;T;F;S;\n\ + \n\ + \n\ + ;;;;;;;\n\ + 2\n\ + 1\n\ + %1%2\n\ + \n\ " for key in locale_keys: @@ -573,6 +656,13 @@ for key in locale_keys: print " " + l['standaloneLongDays'].encode('utf-8') + "" print " " + l['standaloneShortDays'].encode('utf-8') + "" print " " + l['standaloneNarrowDays'].encode('utf-8') + "" + print " " + l['currencyIsoCode'].encode('utf-8') + "" + print " " + l['currencySymbol'].encode('utf-8') + "" + print " " + l['currencyDisplayName'].encode('utf-8') + "" + print " " + str(l['currencyDigits']) + "" + print " " + str(l['currencyRounding']) + "" + print " " + l['currencyFormat'].encode('utf-8') + "" + print " " + l['currencyNegativeFormat'].encode('utf-8') + "" print " " print " " print "" diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index 9bc3c7e6c7..494daf28a9 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -223,6 +223,13 @@ class Locale: 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, country_map): result = {} @@ -336,6 +343,11 @@ def printEscapedString(s): print escapedString(s); +def currencyIsoCodeData(s): + if s: + return ",".join(map(lambda x: str(ord(x)), s)) + return "0,0,0" + def main(): doc = xml.dom.minidom.parse("locale.xml") language_map = loadLanguageMap(doc) @@ -389,6 +401,9 @@ def main(): days_data = StringData() am_data = StringData() pm_data = StringData() + currency_symbol_data = StringData() + currency_display_name_data = StringData() + currency_format_data = StringData() # Locale data print "static const QLocalePrivate locale_data[] = {" @@ -402,7 +417,7 @@ def main(): for key in locale_keys: l = locale_map[key] - print " { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%6d }, // %s/%s" \ + print " { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d }, // %s/%s" \ % (key[0], key[1], l.decimal, l.group, @@ -430,10 +445,17 @@ def main(): days_data.append(l.narrowDays), am_data.append(l.am), pm_data.append(l.pm), + currencyIsoCodeData(l.currencyIsoCode), + currency_symbol_data.append(l.currencySymbol), + currency_display_name_data.append(l.currencyDisplayName), + currency_format_data.append(l.currencyFormat), + currency_format_data.append(l.currencyNegativeFormat), + l.currencyDigits, + l.currencyRounding, l.firstDayOfWeek, l.language, l.country) - print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0 } // trailing 0s" + print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0 } // trailing 0s" print "};" print @@ -494,6 +516,29 @@ def main(): print + # Currency symbol data + #check_static_char_array_length("currency_symbol", currency_symbol_data.data) + print "static const ushort currency_symbol_data[] = {" + print wrap_list(currency_symbol_data.data) + print "};" + + print + + # Currency display name data + #check_static_char_array_length("currency_display_name", currency_display_name_data.data) + print "static const ushort currency_display_name_data[] = {" + print wrap_list(currency_display_name_data.data) + print "};" + + print + + # Currency format data + #check_static_char_array_length("currency_format", currency_format_data.data) + print "static const ushort currency_format_data[] = {" + print wrap_list(currency_format_data.data) + print "};" + + print # Language name list print "static const char language_name_list[] =" print "\"Default\\0\"" diff --git a/util/local_database/xpathlite.py b/util/local_database/xpathlite.py index 95e67110db..502d85d33a 100644 --- a/util/local_database/xpathlite.py +++ b/util/local_database/xpathlite.py @@ -87,6 +87,48 @@ def findChild(parent, tag_name, arg_name=None, arg_value=None, draft=None): return node return False +def findTagsInFile(file, path): + doc = False + if doc_cache.has_key(file): + doc = doc_cache[file] + else: + doc = xml.dom.minidom.parse(file) + doc_cache[file] = doc + + elt = doc.documentElement + tag_spec_list = path.split("/") + last_entry = None + for i in range(len(tag_spec_list)): + tag_spec = tag_spec_list[i] + tag_name = tag_spec + arg_name = 'type' + arg_value = '' + left_bracket = tag_spec.find('[') + if left_bracket != -1: + tag_name = tag_spec[:left_bracket] + arg_value = tag_spec[left_bracket+1:-1].split("=") + if len(arg_value) == 2: + arg_name = arg_value[0] + arg_value = arg_value[1] + else: + arg_value = arg_value[0] + elt = findChild(elt, tag_name, arg_name, arg_value) + if not elt: + return None + ret = [] + if elt.childNodes: + for node in elt.childNodes: + if node.attributes: + element = [node.nodeName, None] + element[1] = node.attributes.items() + ret.append(element) + else: + if elt.attributes: + element = [elt.nodeName, None] + element[1] = elt.attributes.items() + ret.append(element) + return ret + def _findEntryInFile(file, path, draft=None, attribute=None): doc = False if doc_cache.has_key(file): -- cgit v1.2.1 From e0f3dc3ecedb220e5bfa6a54c7c06ef4d371bcc4 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 18 Feb 2011 13:44:52 +0100 Subject: Improved locale data generator the qlocalexml2cpp.py script takes a path to the Qt source tree and patches all files with newly generated data automatically. Reviewed-by: Zeno Albisser --- util/local_database/qlocalexml2cpp.py | 296 ++++++++++++++++++++++------------ 1 file changed, 193 insertions(+), 103 deletions(-) (limited to 'util') diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index 494daf28a9..db549a6608 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -40,7 +40,10 @@ ## ############################################################################# +import os import sys +import tempfile +import datetime import xml.dom.minidom def check_static_char_array_length(name, array): @@ -348,39 +351,59 @@ def currencyIsoCodeData(s): return ",".join(map(lambda x: str(ord(x)), s)) return "0,0,0" +def usage(): + print "Usage: qlocalexml2cpp.py " + sys.exit(1) + +GENERATED_BLOCK_START = "// GENERATED PART STARTS HERE\n" +GENERATED_BLOCK_END = "// GENERATED PART ENDS HERE\n" + def main(): - doc = xml.dom.minidom.parse("locale.xml") + if len(sys.argv) != 3: + usage() + + localexml = sys.argv[1] + qtsrcdir = sys.argv[2] + + if not os.path.exists(qtsrcdir) or not os.path.exists(qtsrcdir): + usage() + if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale_data_p.h"): + usage() + if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.h"): + usage() + + (data_temp_file, data_temp_file_path) = tempfile.mkstemp("qlocale_data_p") + data_temp_file = os.fdopen(data_temp_file, "w") + qlocaledata_file = open(qtsrcdir + "/src/corelib/tools/qlocale_data_p.h", "r") + s = qlocaledata_file.readline() + while s and s != GENERATED_BLOCK_START: + data_temp_file.write(s) + s = qlocaledata_file.readline() + data_temp_file.write(GENERATED_BLOCK_START) + + doc = xml.dom.minidom.parse(localexml) language_map = loadLanguageMap(doc) country_map = loadCountryMap(doc) default_map = loadDefaultMap(doc) locale_map = loadLocaleMap(doc, language_map, country_map) dupes = findDupes(language_map, country_map) - # Language enum - print "enum Language {" - language = "" - for key in language_map.keys(): - language = fixedLanguageName(language_map[key][0], dupes) - print " " + language + " = " + str(key) + "," - print " LastLanguage = " + language - print "};" - - print - - # Country enum - print "enum Country {" - country = "" - for key in country_map.keys(): - country = fixedCountryName(country_map[key][0], dupes) - print " " + country + " = " + str(key) + "," - print " LastCountry = " + country - print "};" - - print + cldr_version = "1.8.1" + data_temp_file.write("\n\ +/*\n\ + This part of the file was generated on %s from the\n\ + Common Locale Data Repository v%s\n\ +\n\ + http://www.unicode.org/cldr/\n\ +\n\ + Do not change it, instead edit CLDR data and regenerate this file using\n\ + cldr2qlocalexml.py and qlocalexml2cpp.py.\n\ +*/\n\n\n\ +" % (str(datetime.date.today()), cldr_version) ) # Locale index - print "static const quint16 locale_index[] = {" - print " 0, // unused" + data_temp_file.write("static const quint16 locale_index[] = {\n") + data_temp_file.write(" 0, // unused\n") index = 0 for key in language_map.keys(): i = 0 @@ -388,11 +411,11 @@ def main(): if count > 0: i = index index += count - print "%6d, // %s" % (i, language_map[key][0]) - print " 0 // trailing 0" - print "};" + data_temp_file.write("%6d, // %s\n" % (i, language_map[key][0])) + data_temp_file.write(" 0 // trailing 0\n") + data_temp_file.write("};\n") - print + data_temp_file.write("\n") date_format_data = StringData() time_format_data = StringData() @@ -406,8 +429,8 @@ def main(): currency_format_data = StringData() # Locale data - print "static const QLocalePrivate locale_data[] = {" - print "// lang terr dec group list prcnt zero minus plus exp sDtFmt lDtFmt sTmFmt lTmFmt ssMonth slMonth sMonth lMonth sDays lDays am,len pm,len" + data_temp_file.write("static const QLocalePrivate locale_data[] = {\n") + data_temp_file.write("// lang terr dec group list prcnt zero minus plus exp sDtFmt lDtFmt sTmFmt lTmFmt ssMonth slMonth sMonth lMonth sDays lDays am,len pm,len\n") locale_keys = locale_map.keys() compareLocaleKeys.default_map = default_map @@ -417,7 +440,7 @@ def main(): for key in locale_keys: l = locale_map[key] - print " { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d }, // %s/%s" \ + data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d }, // %s/%s\n" \ % (key[0], key[1], l.decimal, l.group, @@ -454,157 +477,224 @@ def main(): l.currencyRounding, l.firstDayOfWeek, l.language, - l.country) - print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0 } // trailing 0s" - print "};" + l.country)) + data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0 } // trailing 0s\n") + data_temp_file.write("};\n") - print + data_temp_file.write("\n") # Date format data #check_static_char_array_length("date_format", date_format_data.data) - print "static const ushort date_format_data[] = {" - print wrap_list(date_format_data.data) - print "};" + data_temp_file.write("static const ushort date_format_data[] = {\n") + data_temp_file.write(wrap_list(date_format_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # Time format data #check_static_char_array_length("time_format", time_format_data.data) - print "static const ushort time_format_data[] = {" - print wrap_list(time_format_data.data) - print "};" + data_temp_file.write("static const ushort time_format_data[] = {\n") + data_temp_file.write(wrap_list(time_format_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # Months data #check_static_char_array_length("months", months_data.data) - print "static const ushort months_data[] = {" - print wrap_list(months_data.data) - print "};" + data_temp_file.write("static const ushort months_data[] = {\n") + data_temp_file.write(wrap_list(months_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # Standalone months data #check_static_char_array_length("standalone_months", standalone_months_data.data) - print "static const ushort standalone_months_data[] = {" - print wrap_list(standalone_months_data.data) - print "};" + data_temp_file.write("static const ushort standalone_months_data[] = {\n") + data_temp_file.write(wrap_list(standalone_months_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # Days data #check_static_char_array_length("days", days_data.data) - print "static const ushort days_data[] = {" - print wrap_list(days_data.data) - print "};" + data_temp_file.write("static const ushort days_data[] = {\n") + data_temp_file.write(wrap_list(days_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # AM data #check_static_char_array_length("am", am_data.data) - print "static const ushort am_data[] = {" - print wrap_list(am_data.data) - print "};" + data_temp_file.write("static const ushort am_data[] = {\n") + data_temp_file.write(wrap_list(am_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # PM data #check_static_char_array_length("pm", am_data.data) - print "static const ushort pm_data[] = {" - print wrap_list(pm_data.data) - print "};" + data_temp_file.write("static const ushort pm_data[] = {\n") + data_temp_file.write(wrap_list(pm_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # Currency symbol data #check_static_char_array_length("currency_symbol", currency_symbol_data.data) - print "static const ushort currency_symbol_data[] = {" - print wrap_list(currency_symbol_data.data) - print "};" + data_temp_file.write("static const ushort currency_symbol_data[] = {\n") + data_temp_file.write(wrap_list(currency_symbol_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # Currency display name data #check_static_char_array_length("currency_display_name", currency_display_name_data.data) - print "static const ushort currency_display_name_data[] = {" - print wrap_list(currency_display_name_data.data) - print "};" + data_temp_file.write("static const ushort currency_display_name_data[] = {\n") + data_temp_file.write(wrap_list(currency_display_name_data.data)) + data_temp_file.write("\n};\n") - print + data_temp_file.write("\n") # Currency format data #check_static_char_array_length("currency_format", currency_format_data.data) - print "static const ushort currency_format_data[] = {" - print wrap_list(currency_format_data.data) - print "};" + data_temp_file.write("static const ushort currency_format_data[] = {\n") + data_temp_file.write(wrap_list(currency_format_data.data)) + data_temp_file.write("\n};\n") + + data_temp_file.write("\n") - print # Language name list - print "static const char language_name_list[] =" - print "\"Default\\0\"" + data_temp_file.write("static const char language_name_list[] =\n") + data_temp_file.write("\"Default\\0\"\n") for key in language_map.keys(): - print "\"" + language_map[key][0] + "\\0\"" - print ";" + data_temp_file.write("\"" + language_map[key][0] + "\\0\"\n") + data_temp_file.write(";\n") - print + data_temp_file.write("\n") # Language name index - print "static const quint16 language_name_index[] = {" - print " 0, // Unused" + data_temp_file.write("static const quint16 language_name_index[] = {\n") + data_temp_file.write(" 0, // Unused\n") index = 8 for key in language_map.keys(): language = language_map[key][0] - print "%6d, // %s" % (index, language) + data_temp_file.write("%6d, // %s\n" % (index, language)) index += len(language) + 1 - print "};" + data_temp_file.write("};\n") - print + data_temp_file.write("\n") # Country name list - print "static const char country_name_list[] =" - print "\"Default\\0\"" + data_temp_file.write("static const char country_name_list[] =\n") + data_temp_file.write("\"Default\\0\"\n") for key in country_map.keys(): if key == 0: continue - print "\"" + country_map[key][0] + "\\0\"" - print ";" + data_temp_file.write("\"" + country_map[key][0] + "\\0\"\n") + data_temp_file.write(";\n") - print + data_temp_file.write("\n") # Country name index - print "static const quint16 country_name_index[] = {" - print " 0, // AnyCountry" + data_temp_file.write("static const quint16 country_name_index[] = {\n") + data_temp_file.write(" 0, // AnyCountry\n") index = 8 for key in country_map.keys(): if key == 0: continue country = country_map[key][0] - print "%6d, // %s" % (index, country) + data_temp_file.write("%6d, // %s\n" % (index, country)) index += len(country) + 1 - print "};" + data_temp_file.write("};\n") - print + data_temp_file.write("\n") # Language code list - print "static const unsigned char language_code_list[] =" - print "\" \\0\" // Unused" + data_temp_file.write("static const unsigned char language_code_list[] =\n") + data_temp_file.write("\" \\0\" // Unused\n") for key in language_map.keys(): code = language_map[key][1] if len(code) == 2: code += r"\0" - print "\"%2s\" // %s" % (code, language_map[key][0]) - print ";" + data_temp_file.write("\"%2s\" // %s\n" % (code, language_map[key][0])) + data_temp_file.write(";\n") - print + data_temp_file.write("\n") # Country code list - print "static const unsigned char country_code_list[] =" + data_temp_file.write("static const unsigned char country_code_list[] =\n") for key in country_map.keys(): code = country_map[key][1] if len(code) == 2: code += "\\0" - print "\"%2s\" // %s" % (code, country_map[key][0]) - print ";" + data_temp_file.write("\"%2s\" // %s\n" % (code, country_map[key][0])) + data_temp_file.write(";\n") + + data_temp_file.write("\n") + data_temp_file.write(GENERATED_BLOCK_END) + s = qlocaledata_file.readline() + # skip until end of the block + while s and s != GENERATED_BLOCK_END: + s = qlocaledata_file.readline() + + s = qlocaledata_file.readline() + while s: + data_temp_file.write(s) + s = qlocaledata_file.readline() + data_temp_file.close() + qlocaledata_file.close() + + os.rename(data_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale_data_p.h") + + # qlocale.h + + (qlocale_temp_file, qlocale_temp_file_path) = tempfile.mkstemp("qlocale.h") + qlocale_temp_file = os.fdopen(qlocale_temp_file, "w") + qlocale_file = open(qtsrcdir + "/src/corelib/tools/qlocale.h", "r") + s = qlocale_file.readline() + while s and s != GENERATED_BLOCK_START: + qlocale_temp_file.write(s) + s = qlocale_file.readline() + qlocale_temp_file.write(GENERATED_BLOCK_START) + qlocale_temp_file.write("// see qlocale_data_p.h for more info on generated data\n") + + # Language enum + qlocale_temp_file.write(" enum Language {\n") + language = "" + for key in language_map.keys(): + language = fixedLanguageName(language_map[key][0], dupes) + qlocale_temp_file.write(" " + language + " = " + str(key) + ",\n") + # special cases for norwegian. we really need to make it right at some point. + qlocale_temp_file.write(" NorwegianBokmal = Norwegian,\n") + qlocale_temp_file.write(" NorwegianNynorsk = Nynorsk,\n") + qlocale_temp_file.write(" LastLanguage = " + language + "\n") + qlocale_temp_file.write(" };\n") + + qlocale_temp_file.write("\n") + + # Country enum + qlocale_temp_file.write(" enum Country {\n") + country = "" + for key in country_map.keys(): + country = fixedCountryName(country_map[key][0], dupes) + qlocale_temp_file.write(" " + country + " = " + str(key) + ",\n") + qlocale_temp_file.write(" LastCountry = " + country + "\n") + qlocale_temp_file.write(" };\n") + + qlocale_temp_file.write(GENERATED_BLOCK_END) + s = qlocale_file.readline() + # skip until end of the block + while s and s != GENERATED_BLOCK_END: + s = qlocale_file.readline() + + s = qlocale_file.readline() + while s: + qlocale_temp_file.write(s) + s = qlocale_file.readline() + qlocale_temp_file.close() + qlocale_file.close() + + os.rename(qlocale_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.h") if __name__ == "__main__": -- cgit v1.2.1 From bd7dd9744bb966ea0ff9c6a2ac3c7a4bfa485225 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 18 Feb 2011 15:25:11 +0100 Subject: In the generated locale data add the version info automatically. Reviewed-by: Zeno Albisser --- util/local_database/cldr2qlocalexml.py | 7 +++++++ util/local_database/qlocalexml2cpp.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index 311cf4e02e..b873565c3e 100755 --- a/util/local_database/cldr2qlocalexml.py +++ b/util/local_database/cldr2qlocalexml.py @@ -455,7 +455,14 @@ integrateWeekData(cldr_dir+"/../supplemental/supplementalData.xml") locale_keys = locale_database.keys() locale_keys.sort() +cldr_version = 'unknown' +ldml = open(cldr_dir+"/../dtd/ldml.dtd", "r") +for line in ldml: + if 'version cldrVersion CDATA #FIXED' in line: + cldr_version = line.split('"')[1] + print "" +print " " + cldr_version + "" print " " for id in enumdata.language_list: l = enumdata.language_list[id] diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index db549a6608..edae39cf62 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -388,7 +388,8 @@ def main(): locale_map = loadLocaleMap(doc, language_map, country_map) dupes = findDupes(language_map, country_map) - cldr_version = "1.8.1" + cldr_version = eltText(firstChildElt(doc.documentElement, "version")) + data_temp_file.write("\n\ /*\n\ This part of the file was generated on %s from the\n\ -- cgit v1.2.1 From 368a3259aa678e013078f8bb16a8de173d74759a Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 21 Feb 2011 11:33:43 +0100 Subject: Another improvement to the CLDR parser/QLocale data generator Include the CLDR version used in the QLocale documentation. Reviewed-by: trustme --- util/local_database/qlocalexml2cpp.py | 75 ++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 28 deletions(-) (limited to 'util') diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index edae39cf62..2f998f3f37 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -371,6 +371,8 @@ def main(): usage() if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.h"): usage() + if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.cpp"): + usage() (data_temp_file, data_temp_file_path) = tempfile.mkstemp("qlocale_data_p") data_temp_file = os.fdopen(data_temp_file, "w") @@ -649,54 +651,71 @@ def main(): # qlocale.h - (qlocale_temp_file, qlocale_temp_file_path) = tempfile.mkstemp("qlocale.h") - qlocale_temp_file = os.fdopen(qlocale_temp_file, "w") - qlocale_file = open(qtsrcdir + "/src/corelib/tools/qlocale.h", "r") - s = qlocale_file.readline() + (qlocaleh_temp_file, qlocaleh_temp_file_path) = tempfile.mkstemp("qlocale.h") + qlocaleh_temp_file = os.fdopen(qlocaleh_temp_file, "w") + qlocaleh_file = open(qtsrcdir + "/src/corelib/tools/qlocale.h", "r") + s = qlocaleh_file.readline() while s and s != GENERATED_BLOCK_START: - qlocale_temp_file.write(s) - s = qlocale_file.readline() - qlocale_temp_file.write(GENERATED_BLOCK_START) - qlocale_temp_file.write("// see qlocale_data_p.h for more info on generated data\n") + qlocaleh_temp_file.write(s) + s = qlocaleh_file.readline() + qlocaleh_temp_file.write(GENERATED_BLOCK_START) + qlocaleh_temp_file.write("// see qlocale_data_p.h for more info on generated data\n") # Language enum - qlocale_temp_file.write(" enum Language {\n") + qlocaleh_temp_file.write(" enum Language {\n") language = "" for key in language_map.keys(): language = fixedLanguageName(language_map[key][0], dupes) - qlocale_temp_file.write(" " + language + " = " + str(key) + ",\n") + qlocaleh_temp_file.write(" " + language + " = " + str(key) + ",\n") # special cases for norwegian. we really need to make it right at some point. - qlocale_temp_file.write(" NorwegianBokmal = Norwegian,\n") - qlocale_temp_file.write(" NorwegianNynorsk = Nynorsk,\n") - qlocale_temp_file.write(" LastLanguage = " + language + "\n") - qlocale_temp_file.write(" };\n") + qlocaleh_temp_file.write(" NorwegianBokmal = Norwegian,\n") + qlocaleh_temp_file.write(" NorwegianNynorsk = Nynorsk,\n") + qlocaleh_temp_file.write(" LastLanguage = " + language + "\n") + qlocaleh_temp_file.write(" };\n") - qlocale_temp_file.write("\n") + qlocaleh_temp_file.write("\n") # Country enum - qlocale_temp_file.write(" enum Country {\n") + qlocaleh_temp_file.write(" enum Country {\n") country = "" for key in country_map.keys(): country = fixedCountryName(country_map[key][0], dupes) - qlocale_temp_file.write(" " + country + " = " + str(key) + ",\n") - qlocale_temp_file.write(" LastCountry = " + country + "\n") - qlocale_temp_file.write(" };\n") + qlocaleh_temp_file.write(" " + country + " = " + str(key) + ",\n") + qlocaleh_temp_file.write(" LastCountry = " + country + "\n") + qlocaleh_temp_file.write(" };\n") - qlocale_temp_file.write(GENERATED_BLOCK_END) - s = qlocale_file.readline() + qlocaleh_temp_file.write(GENERATED_BLOCK_END) + s = qlocaleh_file.readline() # skip until end of the block while s and s != GENERATED_BLOCK_END: - s = qlocale_file.readline() + s = qlocaleh_file.readline() - s = qlocale_file.readline() + s = qlocaleh_file.readline() while s: - qlocale_temp_file.write(s) - s = qlocale_file.readline() - qlocale_temp_file.close() - qlocale_file.close() + qlocaleh_temp_file.write(s) + s = qlocaleh_file.readline() + qlocaleh_temp_file.close() + qlocaleh_file.close() + + os.rename(qlocaleh_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.h") + + # qlocale.cpp - os.rename(qlocale_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.h") + (qlocalecpp_temp_file, qlocalecpp_temp_file_path) = tempfile.mkstemp("qlocale.cpp") + qlocalecpp_temp_file = os.fdopen(qlocalecpp_temp_file, "w") + qlocalecpp_file = open(qtsrcdir + "/src/corelib/tools/qlocale.cpp", "r") + s = qlocalecpp_file.readline() + DOCSTRING=" QLocale's data is based on Common Locale Data Repository " + while s: + if DOCSTRING in s: + qlocalecpp_temp_file.write(DOCSTRING + "v" + cldr_version + ".\n") + else: + qlocalecpp_temp_file.write(s) + s = qlocalecpp_file.readline() + qlocalecpp_temp_file.close() + qlocalecpp_file.close() + os.rename(qlocalecpp_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.cpp") if __name__ == "__main__": main() -- cgit v1.2.1 From aa9bc750eb72a180f15be144d2cc6621289f59f5 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Wed, 16 Feb 2011 14:18:22 +0100 Subject: Implemented QLocale::quoteString(...) Reviewed-by: Denis Dzyubenko Task-number: QTBUG-17096 --- util/local_database/cldr2qlocalexml.py | 12 ++++++++++++ util/local_database/qlocalexml2cpp.py | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'util') diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index b873565c3e..0bc166408a 100755 --- a/util/local_database/cldr2qlocalexml.py +++ b/util/local_database/cldr2qlocalexml.py @@ -199,6 +199,10 @@ def generateLocaleInfo(path): result['minus'] = get_number_in_system(path, "numbers/symbols/minusSign", numbering_system) result['plus'] = get_number_in_system(path, "numbers/symbols/plusSign", numbering_system) result['exp'] = get_number_in_system(path, "numbers/symbols/exponential", numbering_system).lower() + result['quotationStart'] = findEntry(path, "delimiters/quotationStart") + result['quotationEnd'] = findEntry(path, "delimiters/quotationEnd") + result['alternateQuotationStart'] = findEntry(path, "delimiters/alternateQuotationStart") + result['alternateQuotationEnd'] = findEntry(path, "delimiters/alternateQuotationEnd") result['am'] = findEntry(path, "dates/calendars/calendar[gregorian]/dayPeriods/dayPeriodContext[format]/dayPeriodWidth[wide]/dayPeriod[am]", draft) result['pm'] = findEntry(path, "dates/calendars/calendar[gregorian]/dayPeriods/dayPeriodContext[format]/dayPeriodWidth[wide]/dayPeriod[pm]", draft) result['longDateFormat'] = convert_date(findEntry(path, "dates/calendars/calendar[gregorian]/dateFormats/dateFormatLength[full]/dateFormat/pattern")) @@ -600,6 +604,10 @@ print \ 45\n\ 43\n\ 101\n\ + \"\n\ + \"\n\ + \'\n\ + \'\n\ AM\n\ PM\n\ mon\n\ @@ -644,6 +652,10 @@ for key in locale_keys: print " " + ordStr(l['minus']) + "" print " " + ordStr(l['plus']) + "" print " " + fixOrdStrExp(l['exp']) + "" + print " " + l['quotationStart'].encode('utf-8') + "" + print " " + l['quotationEnd'].encode('utf-8') + "" + print " " + l['alternateQuotationStart'].encode('utf-8') + "" + print " " + l['alternateQuotationEnd'].encode('utf-8') + "" print " " + l['am'].encode('utf-8') + "" print " " + l['pm'].encode('utf-8') + "" print " " + l['firstDayOfWeek'].encode('utf-8') + "" diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index 2f998f3f37..6b8fdb9808 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -195,6 +195,10 @@ 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")) @@ -207,6 +211,10 @@ class Locale: 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.am = eltText(firstChildElt(elt, "am")) self.pm = eltText(firstChildElt(elt, "pm")) self.firstDayOfWeek = convertToQtDayOfWeek(eltText(firstChildElt(elt, "firstDayOfWeek"))) @@ -433,7 +441,7 @@ def main(): # Locale data data_temp_file.write("static const QLocalePrivate locale_data[] = {\n") - data_temp_file.write("// lang terr dec group list prcnt zero minus plus exp sDtFmt lDtFmt sTmFmt lTmFmt ssMonth slMonth sMonth lMonth sDays lDays am,len pm,len\n") + data_temp_file.write("// lang terr dec group list prcnt zero minus plus exp quotStart quotEnd altQuotStart altQuotEnd sDtFmt lDtFmt sTmFmt lTmFmt ssMonth slMonth sMonth lMonth sDays lDays am,len pm,len\n") locale_keys = locale_map.keys() compareLocaleKeys.default_map = default_map @@ -443,7 +451,7 @@ def main(): for key in locale_keys: l = locale_map[key] - data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d }, // %s/%s\n" \ + data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d }, // %s/%s\n" \ % (key[0], key[1], l.decimal, l.group, @@ -453,6 +461,10 @@ def main(): l.minus, l.plus, l.exp, + l.quotationStart, + l.quotationEnd, + l.alternateQuotationStart, + l.alternateQuotationEnd, date_format_data.append(l.shortDateFormat), date_format_data.append(l.longDateFormat), time_format_data.append(l.shortTimeFormat), @@ -481,7 +493,7 @@ def main(): l.firstDayOfWeek, l.language, l.country)) - data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0 } // trailing 0s\n") + data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0 } // trailing 0s\n") data_temp_file.write("};\n") data_temp_file.write("\n") -- cgit v1.2.1 From 3def7f4dd09f5d93f90d20eaedd17d8bd8c4a6fd Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Tue, 22 Feb 2011 15:41:59 +0100 Subject: Implemented QLocale::weekendStart and QLocale::weekendEnd Reviewed-by: Denis Dzyubenko Task-number: QTBUG-17088 --- util/local_database/cldr2qlocalexml.py | 62 ++++++++++++++++++++++++++++++++++ util/local_database/qlocalexml2cpp.py | 8 +++-- 2 files changed, 68 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index 0bc166408a..c70cf184bc 100755 --- a/util/local_database/cldr2qlocalexml.py +++ b/util/local_database/cldr2qlocalexml.py @@ -413,6 +413,22 @@ def integrateWeekData(filePath): satFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=sat]", attribute="territories")[0].split(" ") sunFirstDayIn = findEntryInFile(filePath, "weekData/firstDay[day=sun]", attribute="territories")[0].split(" ") + monWeekendStart = findEntryInFile(filePath, "weekData/weekendStart[day=mon]", attribute="territories")[0].split(" ") + tueWeekendStart = findEntryInFile(filePath, "weekData/weekendStart[day=tue]", attribute="territories")[0].split(" ") + wedWeekendStart = findEntryInFile(filePath, "weekData/weekendStart[day=wed]", attribute="territories")[0].split(" ") + thuWeekendStart = findEntryInFile(filePath, "weekData/weekendStart[day=thu]", attribute="territories")[0].split(" ") + friWeekendStart = findEntryInFile(filePath, "weekData/weekendStart[day=fri]", attribute="territories")[0].split(" ") + satWeekendStart = findEntryInFile(filePath, "weekData/weekendStart[day=sat]", attribute="territories")[0].split(" ") + sunWeekendStart = findEntryInFile(filePath, "weekData/weekendStart[day=sun]", attribute="territories")[0].split(" ") + + monWeekendEnd = findEntryInFile(filePath, "weekData/weekendEnd[day=mon]", attribute="territories")[0].split(" ") + tueWeekendEnd = findEntryInFile(filePath, "weekData/weekendEnd[day=tue]", attribute="territories")[0].split(" ") + wedWeekendEnd = findEntryInFile(filePath, "weekData/weekendEnd[day=wed]", attribute="territories")[0].split(" ") + thuWeekendEnd = findEntryInFile(filePath, "weekData/weekendEnd[day=thu]", attribute="territories")[0].split(" ") + friWeekendEnd = findEntryInFile(filePath, "weekData/weekendEnd[day=fri]", attribute="territories")[0].split(" ") + satWeekendEnd = findEntryInFile(filePath, "weekData/weekendEnd[day=sat]", attribute="territories")[0].split(" ") + sunWeekendEnd = findEntryInFile(filePath, "weekData/weekendEnd[day=sun]", attribute="territories")[0].split(" ") + firstDayByCountryCode = {} for countryCode in monFirstDayIn: firstDayByCountryCode[countryCode] = "mon" @@ -429,6 +445,38 @@ def integrateWeekData(filePath): for countryCode in sunFirstDayIn: firstDayByCountryCode[countryCode] = "sun" + weekendStartByCountryCode = {} + for countryCode in monWeekendStart: + weekendStartByCountryCode[countryCode] = "mon" + for countryCode in tueWeekendStart: + weekendStartByCountryCode[countryCode] = "tue" + for countryCode in wedWeekendStart: + weekendStartByCountryCode[countryCode] = "wed" + for countryCode in thuWeekendStart: + weekendStartByCountryCode[countryCode] = "thu" + for countryCode in friWeekendStart: + weekendStartByCountryCode[countryCode] = "fri" + for countryCode in satWeekendStart: + weekendStartByCountryCode[countryCode] = "sat" + for countryCode in sunWeekendStart: + weekendStartByCountryCode[countryCode] = "sun" + + weekendEndByCountryCode = {} + for countryCode in monWeekendEnd: + weekendEndByCountryCode[countryCode] = "mon" + for countryCode in tueWeekendEnd: + weekendEndByCountryCode[countryCode] = "tue" + for countryCode in wedWeekendEnd: + weekendEndByCountryCode[countryCode] = "wed" + for countryCode in thuWeekendEnd: + weekendEndByCountryCode[countryCode] = "thu" + for countryCode in friWeekendEnd: + weekendEndByCountryCode[countryCode] = "fri" + for countryCode in satWeekendEnd: + weekendEndByCountryCode[countryCode] = "sat" + for countryCode in sunWeekendEnd: + weekendEndByCountryCode[countryCode] = "sun" + for (key,locale) in locale_database.iteritems(): countryCode = locale['country_code'] if countryCode in firstDayByCountryCode: @@ -436,6 +484,16 @@ def integrateWeekData(filePath): else: locale_database[key]['firstDayOfWeek'] = firstDayByCountryCode["001"] + if countryCode in weekendStartByCountryCode: + locale_database[key]['weekendStart'] = weekendStartByCountryCode[countryCode] + else: + locale_database[key]['weekendStart'] = weekendStartByCountryCode["001"] + + if countryCode in weekendEndByCountryCode: + locale_database[key]['weekendEnd'] = weekendEndByCountryCode[countryCode] + else: + locale_database[key]['weekendEnd'] = weekendEndByCountryCode["001"] + if len(sys.argv) != 2: usage() @@ -611,6 +669,8 @@ print \ AM\n\ PM\n\ mon\n\ + sat\n\ + sun\n\ EEEE, d MMMM yyyy\n\ d MMM yyyy\n\ HH:mm:ss z\n\ @@ -659,6 +719,8 @@ for key in locale_keys: print " " + l['am'].encode('utf-8') + "" print " " + l['pm'].encode('utf-8') + "" print " " + l['firstDayOfWeek'].encode('utf-8') + "" + print " " + l['weekendStart'].encode('utf-8') + "" + print " " + l['weekendEnd'].encode('utf-8') + "" print " " + l['longDateFormat'].encode('utf-8') + "" print " " + l['shortDateFormat'].encode('utf-8') + "" print " " + l['longTimeFormat'].encode('utf-8') + "" diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index 6b8fdb9808..86adf90b1c 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -218,6 +218,8 @@ class Locale: 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"))) @@ -451,7 +453,7 @@ def main(): for key in locale_keys: l = locale_map[key] - data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d }, // %s/%s\n" \ + data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d,%6d,%6d }, // %s/%s\n" \ % (key[0], key[1], l.decimal, l.group, @@ -491,9 +493,11 @@ def main(): l.currencyDigits, l.currencyRounding, l.firstDayOfWeek, + l.weekendStart, + l.weekendEnd, l.language, l.country)) - data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0 } // trailing 0s\n") + data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0, 0, 0 } // trailing 0s\n") data_temp_file.write("};\n") data_temp_file.write("\n") -- cgit v1.2.1 From bdc74c482973c4658e6ac9d6889411bf0c791432 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 25 Feb 2011 19:00:09 +0100 Subject: Fixed the generator script for qlocale after splitting the sources. Reviewed-by: trustme --- util/local_database/qlocalexml2cpp.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'util') diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index 86adf90b1c..ee66ba9fb9 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -381,7 +381,7 @@ def main(): usage() if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.h"): usage() - if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.cpp"): + if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.qdoc"): usage() (data_temp_file, data_temp_file_path) = tempfile.mkstemp("qlocale_data_p") @@ -715,23 +715,23 @@ def main(): os.rename(qlocaleh_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.h") - # qlocale.cpp + # qlocale.qdoc - (qlocalecpp_temp_file, qlocalecpp_temp_file_path) = tempfile.mkstemp("qlocale.cpp") - qlocalecpp_temp_file = os.fdopen(qlocalecpp_temp_file, "w") - qlocalecpp_file = open(qtsrcdir + "/src/corelib/tools/qlocale.cpp", "r") - s = qlocalecpp_file.readline() + (qlocaleqdoc_temp_file, qlocaleqdoc_temp_file_path) = tempfile.mkstemp("qlocale.qdoc") + qlocaleqdoc_temp_file = os.fdopen(qlocaleqdoc_temp_file, "w") + qlocaleqdoc_file = open(qtsrcdir + "/src/corelib/tools/qlocale.qdoc", "r") + s = qlocaleqdoc_file.readline() DOCSTRING=" QLocale's data is based on Common Locale Data Repository " while s: if DOCSTRING in s: - qlocalecpp_temp_file.write(DOCSTRING + "v" + cldr_version + ".\n") + qlocaleqdoc_temp_file.write(DOCSTRING + "v" + cldr_version + ".\n") else: - qlocalecpp_temp_file.write(s) - s = qlocalecpp_file.readline() - qlocalecpp_temp_file.close() - qlocalecpp_file.close() + qlocaleqdoc_temp_file.write(s) + s = qlocaleqdoc_file.readline() + qlocaleqdoc_temp_file.close() + qlocaleqdoc_file.close() - os.rename(qlocalecpp_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.cpp") + os.rename(qlocaleqdoc_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.qdoc") if __name__ == "__main__": main() -- cgit v1.2.1 From 803c374749fb0ab37512be0ad625d9823d93067b Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Tue, 1 Mar 2011 12:05:47 +0100 Subject: Fixed CLDR to QLocale generator. Create temp files on the same device as the QTDIR so that rename() will work properly. Reviewed-by: Liang Qi --- util/local_database/qlocalexml2cpp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'util') diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index ee66ba9fb9..8b68984609 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -384,7 +384,7 @@ def main(): if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.qdoc"): usage() - (data_temp_file, data_temp_file_path) = tempfile.mkstemp("qlocale_data_p") + (data_temp_file, data_temp_file_path) = tempfile.mkstemp("qlocale_data_p", dir=qtsrcdir) data_temp_file = os.fdopen(data_temp_file, "w") qlocaledata_file = open(qtsrcdir + "/src/corelib/tools/qlocale_data_p.h", "r") s = qlocaledata_file.readline() @@ -667,7 +667,7 @@ def main(): # qlocale.h - (qlocaleh_temp_file, qlocaleh_temp_file_path) = tempfile.mkstemp("qlocale.h") + (qlocaleh_temp_file, qlocaleh_temp_file_path) = tempfile.mkstemp("qlocale.h", dir=qtsrcdir) qlocaleh_temp_file = os.fdopen(qlocaleh_temp_file, "w") qlocaleh_file = open(qtsrcdir + "/src/corelib/tools/qlocale.h", "r") s = qlocaleh_file.readline() @@ -717,7 +717,7 @@ def main(): # qlocale.qdoc - (qlocaleqdoc_temp_file, qlocaleqdoc_temp_file_path) = tempfile.mkstemp("qlocale.qdoc") + (qlocaleqdoc_temp_file, qlocaleqdoc_temp_file_path) = tempfile.mkstemp("qlocale.qdoc", dir=qtsrcdir) qlocaleqdoc_temp_file = os.fdopen(qlocaleqdoc_temp_file, "w") qlocaleqdoc_file = open(qtsrcdir + "/src/corelib/tools/qlocale.qdoc", "r") s = qlocaleqdoc_file.readline() -- cgit v1.2.1 From 440394d05989e1d20f82071045106117e907a378 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 28 Feb 2011 18:48:36 +0100 Subject: Added writing script support to QLocale. Task-number: QTBUG-17105 Reviewed-by: trustme --- util/local_database/cldr2qlocalexml.py | 31 ++++++- util/local_database/enumdata.py | 20 +++++ util/local_database/qlocalexml2cpp.py | 148 ++++++++++++++++++++++++++++----- 3 files changed, 177 insertions(+), 22 deletions(-) (limited to 'util') diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index c70cf184bc..fb0e5db02d 100755 --- a/util/local_database/cldr2qlocalexml.py +++ b/util/local_database/cldr2qlocalexml.py @@ -120,8 +120,10 @@ def generateLocaleInfo(path): if not country_code: return {} - # we do not support scripts and variants - if variant_code or script_code: + # we do not support variants + # ### actually there is only one locale with variant: en_US_POSIX + # does anybody care about it at all? + if variant_code: return {} language_id = enumdata.languageCodeToId(language_code) @@ -130,6 +132,14 @@ def generateLocaleInfo(path): return {} language = enumdata.language_list[language_id][0] + script_id = enumdata.scriptCodeToId(script_code) + if script_code == -1: + sys.stderr.write("unnknown script code \"" + script_code + "\"\n") + return {} + script = "AnyScript" + if script_id != -1: + script = enumdata.script_list[script_id][0] + country_id = enumdata.countryCodeToId(country_code) country = "" if country_id != -1: @@ -146,12 +156,14 @@ def generateLocaleInfo(path): result = {} result['language'] = language + result['script'] = script result['country'] = country result['language_code'] = language_code result['country_code'] = country_code result['script_code'] = script_code result['variant_code'] = variant_code result['language_id'] = language_id + result['script_id'] = script_id result['country_id'] = country_id supplementalPath = dir_name + "/../supplemental/supplementalData.xml" @@ -511,7 +523,7 @@ for file in cldr_files: sys.stderr.write("skipping file \"" + file + "\"\n") continue - locale_database[(l['language_id'], l['country_id'], l['script_code'], 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() @@ -535,6 +547,16 @@ for id in enumdata.language_list: print " " print " " +print " " +for id in enumdata.script_list: + l = enumdata.script_list[id] + print " " +print " " + print " " for id in enumdata.country_list: l = enumdata.country_list[id] @@ -653,6 +675,7 @@ print " " print \ " \n\ C\n\ + \n\ AnyCountry\n\ 46\n\ 44\n\ @@ -701,8 +724,10 @@ for key in locale_keys: print " " print " " + l['language'] + "" + print " " print " " + l['country'] + "" print " " + l['language_code'] + "" + print " " + l['script_code'] + "" print " " + l['country_code'] + "" print " " + ordStr(l['decimal']) + "" print " " + ordStr(l['group']) + "" diff --git a/util/local_database/enumdata.py b/util/local_database/enumdata.py index e957349c85..9e0d7d8ddd 100644 --- a/util/local_database/enumdata.py +++ b/util/local_database/enumdata.py @@ -45,6 +45,7 @@ # need to be *appended* to this list. language_list = { + 0 : [ "AnyLanguage", " " ], 1 : [ "C", " " ], 2 : [ "Abkhazian", "ab" ], 3 : [ "Afan", "om" ], @@ -511,6 +512,19 @@ country_list = { 246 : [ "LatinAmericaAndTheCaribbean", "419" ] } +script_list = { + 0 : [ "AnyScript", "" ], + 1 : [ "Arabic", "Arab" ], + 2 : [ "Cyrillic", "Cyrl" ], + 3 : [ "Deseret", "Dsrt" ], + 4 : [ "Gurmukhi", "Guru" ], + 5 : [ "Simplified Han", "Hans" ], + 6 : [ "Traditional Han", "Hant" ], + 7 : [ "Latin", "Latn" ], + 8 : [ "Mongolian", "Mong" ], + 9 : [ "Tifinagh", "Tfng" ] +} + def countryCodeToId(code): for country_id in country_list: if country_list[country_id][1] == code: @@ -522,3 +536,9 @@ def languageCodeToId(code): if language_list[language_id][1] == code: return language_id return -1 + +def scriptCodeToId(code): + for script_id in script_list: + if script_list[script_id][1] == code: + return script_id + return -1 diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index 8b68984609..b8e4e896da 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -46,6 +46,12 @@ import tempfile import datetime import xml.dom.minidom +class Error: + def __init__(self, msg): + self.msg = msg + def __str__(self): + return self.msg + def check_static_char_array_length(name, array): # some compilers like VC6 doesn't allow static arrays more than 64K bytes size. size = reduce(lambda x, y: x+len(escapedString(y)), array, 0) @@ -103,6 +109,20 @@ def loadLanguageMap(doc): return result +def loadScriptMap(doc): + result = {} + + script_list_elt = firstChildElt(doc.documentElement, "scriptList") + script_elt = firstChildElt(script_list_elt, "script") + while script_elt: + script_id = int(eltText(firstChildElt(script_elt, "id"))) + script_name = eltText(firstChildElt(script_elt, "name")) + script_code = eltText(firstChildElt(script_elt, "code")) + result[script_id] = (script_name, script_code) + script_elt = nextSiblingElt(script_elt, "script") + + return result + def loadCountryMap(doc): result = {} @@ -129,6 +149,15 @@ def loadDefaultMap(doc): elt = nextSiblingElt(elt, "defaultCountry"); return result +def fixedScriptName(name, dupes): + name = name.replace(" ", "") + if name[-6:] != "Script": + name = name + "Script"; + if name in dupes: + sys.stderr.write("\n\n\nERROR: The script name '%s' is messy" % name) + sys.exit(1); + return name + def fixedCountryName(name, dupes): if name in dupes: return name.replace(" ", "") + "Country" @@ -150,6 +179,12 @@ def languageNameToId(name, language_map): return key return -1 +def scriptNameToId(name, script_map): + for key in script_map.keys(): + if script_map[key][0] == name: + return key + return -1 + def countryNameToId(name, country_map): for key in country_map.keys(): if country_map[key][0] == name: @@ -202,6 +237,7 @@ def assertSingleChar(string): class Locale: def __init__(self, elt): self.language = eltText(firstChildElt(elt, "language")) + self.script = eltText(firstChildElt(elt, "script")) self.country = eltText(firstChildElt(elt, "country")) self.decimal = int(eltText(firstChildElt(elt, "decimal"))) self.group = int(eltText(firstChildElt(elt, "group"))) @@ -244,7 +280,7 @@ class Locale: self.currencyFormat = eltText(firstChildElt(elt, "currencyFormat")) self.currencyNegativeFormat = eltText(firstChildElt(elt, "currencyNegativeFormat")) -def loadLocaleMap(doc, language_map, country_map): +def loadLocaleMap(doc, language_map, script_map, country_map): result = {} locale_list_elt = firstChildElt(doc.documentElement, "localeList") @@ -253,11 +289,14 @@ def loadLocaleMap(doc, language_map, country_map): locale = Locale(locale_elt) language_id = languageNameToId(locale.language, language_map) if language_id == -1: - sys.stderr.write("Cannot find a language id for %s\n" % locale.language) + sys.stderr.write("Cannot find a language id for '%s'\n" % locale.language) + script_id = scriptNameToId(locale.script, script_map) + if script_id == -1: + sys.stderr.write("Cannot find a script id for '%s'\n" % locale.script) country_id = countryNameToId(locale.country, country_map) if country_id == -1: - sys.stderr.write("Cannot find a country id for %s\n" % locale.country) - result[(language_id, country_id)] = locale + sys.stderr.write("Cannot find a country id for '%s'\n" % locale.country) + result[(language_id, script_id, country_id)] = locale locale_elt = nextSiblingElt(locale_elt, "locale") @@ -273,14 +312,17 @@ def compareLocaleKeys(key1, key2): if l1.language in compareLocaleKeys.default_map: default = compareLocaleKeys.default_map[l1.language] - if l1.country == default: + if l1.country == default and key1[1] == 0: return -1 - if l2.country == default: + if l2.country == default and key2[1] == 0: return 1 + + if key1[1] != key2[1]: + return key1[1] - key2[1] else: return key1[0] - key2[0] - return key1[1] - key2[1] + return key1[2] - key2[2] def languageCount(language_id, locale_map): @@ -290,8 +332,25 @@ def languageCount(language_id, locale_map): result += 1 return result +def unicode2hex(s): + lst = [] + for x in s: + v = ord(x) + if v > 0xFFFF: + # make a surrogate pair + # copied from qchar.h + high = (v >> 10) + 0xd7c0 + low = (v % 0x400 + 0xdc00) + lst.append(hex(high)) + lst.append(hex(low)) + else: + lst.append(hex(v)) + return lst + class StringDataToken: def __init__(self, index, length): + if index > 0xFFFF or length > 0xFFFF: + raise Error("Position exceeds ushort range: %d,%d " % (index, length)) self.index = index self.length = length def __str__(self): @@ -305,9 +364,9 @@ class StringData: if s in self.hash: return self.hash[s] - lst = map(lambda x: hex(ord(x)), s) + lst = unicode2hex(s) index = len(self.data) - if index >= 65535: + if index > 65535: print "\n\n\n#error Data index is too big!" sys.stderr.write ("\n\n\nERROR: index exceeds the uint16 range! index = %d\n" % index) sys.exit(1) @@ -316,7 +375,12 @@ class StringData: print "\n\n\n#error Data is too big!" sys.stderr.write ("\n\n\nERROR: data size exceeds the uint16 range! size = %d\n" % size) sys.exit(1) - token = StringDataToken(index, size) + token = None + try: + token = StringDataToken(index, size) + except Error as e: + sys.stderr.write("\n\n\nERROR: %s: on data '%s'" % (e, s)) + sys.exit(1) self.hash[s] = token self.data += lst return token @@ -395,9 +459,10 @@ def main(): doc = xml.dom.minidom.parse(localexml) language_map = loadLanguageMap(doc) + script_map = loadScriptMap(doc) country_map = loadCountryMap(doc) default_map = loadDefaultMap(doc) - locale_map = loadLocaleMap(doc, language_map, country_map) + locale_map = loadLocaleMap(doc, language_map, script_map, country_map) dupes = findDupes(language_map, country_map) cldr_version = eltText(firstChildElt(doc.documentElement, "version")) @@ -416,7 +481,6 @@ def main(): # Locale index data_temp_file.write("static const quint16 locale_index[] = {\n") - data_temp_file.write(" 0, // unused\n") index = 0 for key in language_map.keys(): i = 0 @@ -443,7 +507,7 @@ def main(): # Locale data data_temp_file.write("static const QLocalePrivate locale_data[] = {\n") - data_temp_file.write("// lang terr dec group list prcnt zero minus plus exp quotStart quotEnd altQuotStart altQuotEnd sDtFmt lDtFmt sTmFmt lTmFmt ssMonth slMonth sMonth lMonth sDays lDays am,len pm,len\n") + data_temp_file.write("// lang script terr dec group list prcnt zero minus plus exp quotStart quotEnd altQuotStart altQuotEnd sDtFmt lDtFmt sTmFmt lTmFmt ssMonth slMonth sMonth lMonth sDays lDays am,len pm,len\n") locale_keys = locale_map.keys() compareLocaleKeys.default_map = default_map @@ -452,9 +516,8 @@ def main(): for key in locale_keys: l = locale_map[key] - - data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d,%6d,%6d }, // %s/%s\n" \ - % (key[0], key[1], + data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d,%6d,%6d }, // %s/%s/%s\n" \ + % (key[0], key[1], key[2], l.decimal, l.group, l.listDelim, @@ -496,8 +559,9 @@ def main(): l.weekendStart, l.weekendEnd, l.language, + l.script, l.country)) - data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0, 0, 0 } // trailing 0s\n") + data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0, 0, 0 } // trailing 0s\n") data_temp_file.write("};\n") data_temp_file.write("\n") @@ -586,6 +650,8 @@ def main(): data_temp_file.write("static const char language_name_list[] =\n") data_temp_file.write("\"Default\\0\"\n") for key in language_map.keys(): + if key == 0: + continue data_temp_file.write("\"" + language_map[key][0] + "\\0\"\n") data_temp_file.write(";\n") @@ -593,9 +659,11 @@ def main(): # Language name index data_temp_file.write("static const quint16 language_name_index[] = {\n") - data_temp_file.write(" 0, // Unused\n") + data_temp_file.write(" 0, // AnyLanguage\n") index = 8 for key in language_map.keys(): + if key == 0: + continue language = language_map[key][0] data_temp_file.write("%6d, // %s\n" % (index, language)) index += len(language) + 1 @@ -603,6 +671,31 @@ def main(): data_temp_file.write("\n") + # Script name list + data_temp_file.write("static const char script_name_list[] =\n") + data_temp_file.write("\"Default\\0\"\n") + for key in script_map.keys(): + if key == 0: + continue + data_temp_file.write("\"" + script_map[key][0] + "\\0\"\n") + data_temp_file.write(";\n") + + data_temp_file.write("\n") + + # Script name index + data_temp_file.write("static const quint16 script_name_index[] = {\n") + data_temp_file.write(" 0, // AnyScript\n") + index = 8 + for key in script_map.keys(): + if key == 0: + continue + script = script_map[key][0] + data_temp_file.write("%6d, // %s\n" % (index, script)) + index += len(script) + 1 + data_temp_file.write("};\n") + + data_temp_file.write("\n") + # Country name list data_temp_file.write("static const char country_name_list[] =\n") data_temp_file.write("\"Default\\0\"\n") @@ -630,7 +723,6 @@ def main(): # Language code list data_temp_file.write("static const unsigned char language_code_list[] =\n") - data_temp_file.write("\" \\0\" // Unused\n") for key in language_map.keys(): code = language_map[key][1] if len(code) == 2: @@ -640,6 +732,15 @@ def main(): data_temp_file.write("\n") + # Script code list + data_temp_file.write("static const unsigned char script_code_list[] =\n") + for key in script_map.keys(): + code = script_map[key][1] + for i in range(4 - len(code)): + code += "\\0" + data_temp_file.write("\"%2s\" // %s\n" % (code, script_map[key][0])) + data_temp_file.write(";\n") + # Country code list data_temp_file.write("static const unsigned char country_code_list[] =\n") for key in country_map.keys(): @@ -691,6 +792,15 @@ def main(): qlocaleh_temp_file.write("\n") + # Script enum + qlocaleh_temp_file.write(" enum Script {\n") + script = "" + for key in script_map.keys(): + script = fixedScriptName(script_map[key][0], dupes) + qlocaleh_temp_file.write(" " + script + " = " + str(key) + ",\n") + qlocaleh_temp_file.write(" LastScript = " + script + "\n") + qlocaleh_temp_file.write(" };\n") + # Country enum qlocaleh_temp_file.write(" enum Country {\n") country = "" -- cgit v1.2.1 From 2a21c69a038c6aeee23b249ac70572a92f27ec1a Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 4 Mar 2011 14:52:27 +0100 Subject: Added convenience script enum values to QLocale. Apparently SimplifiedHan and TraditionalHan are not widely used terms, hence adding convenience names SimplifiedChineseScript and TraditionalChineseScript. Also added the missing documentation for the Script enum. Reviewed-by: trustme --- util/local_database/qlocalexml2cpp.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'util') diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index b8e4e896da..cf1ced6509 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -798,6 +798,8 @@ def main(): for key in script_map.keys(): script = fixedScriptName(script_map[key][0], dupes) qlocaleh_temp_file.write(" " + script + " = " + str(key) + ",\n") + qlocaleh_temp_file.write(" SimplifiedChineseScript = SimplifiedHanScript,\n") + qlocaleh_temp_file.write(" TraditionalChineseScript = TraditionalHanScript,\n") qlocaleh_temp_file.write(" LastScript = " + script + "\n") qlocaleh_temp_file.write(" };\n") -- cgit v1.2.1 From 09fe2cd62df80373e602d47c570ae317a60a5293 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 8 Mar 2011 17:32:24 +0100 Subject: Using list patterns to get a string from list in QLocale. Reviewed-by: Denis Dzyubenko Task-number: QTBUG-17097 --- util/local_database/cldr2qlocalexml.py | 20 ++++++++++++++++++++ util/local_database/qlocalexml2cpp.py | 23 ++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) (limited to 'util') diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index fb0e5db02d..a67971bde6 100755 --- a/util/local_database/cldr2qlocalexml.py +++ b/util/local_database/cldr2qlocalexml.py @@ -82,6 +82,14 @@ def parse_number_format(patterns, data): result.append(pattern) return result +def parse_list_pattern_part_format(pattern): + # this is a very limited parsing of the format for list pattern part only. + result = "" + result = pattern.replace("{0}", "%1") + result = result.replace("{1}", "%2") + result = result.replace("{2}", "%3") + return result + def ordStr(c): if len(c) == 1: return str(ord(c)) @@ -215,6 +223,10 @@ def generateLocaleInfo(path): result['quotationEnd'] = findEntry(path, "delimiters/quotationEnd") result['alternateQuotationStart'] = findEntry(path, "delimiters/alternateQuotationStart") result['alternateQuotationEnd'] = findEntry(path, "delimiters/alternateQuotationEnd") + result['listPatternPartStart'] = parse_list_pattern_part_format(findEntry(path, "listPatterns/listPattern/listPatternPart[start]")) + result['listPatternPartMiddle'] = parse_list_pattern_part_format(findEntry(path, "listPatterns/listPattern/listPatternPart[middle]")) + result['listPatternPartEnd'] = parse_list_pattern_part_format(findEntry(path, "listPatterns/listPattern/listPatternPart[end]")) + result['listPatternPartTwo'] = parse_list_pattern_part_format(findEntry(path, "listPatterns/listPattern/listPatternPart[2]")) result['am'] = findEntry(path, "dates/calendars/calendar[gregorian]/dayPeriods/dayPeriodContext[format]/dayPeriodWidth[wide]/dayPeriod[am]", draft) result['pm'] = findEntry(path, "dates/calendars/calendar[gregorian]/dayPeriods/dayPeriodContext[format]/dayPeriodWidth[wide]/dayPeriod[pm]", draft) result['longDateFormat'] = convert_date(findEntry(path, "dates/calendars/calendar[gregorian]/dateFormats/dateFormatLength[full]/dateFormat/pattern")) @@ -689,6 +701,10 @@ print \ \"\n\ \'\n\ \'\n\ + %1, %2\n\ + %1, %2\n\ + %1, %2\n\ + %1, %2\n\ AM\n\ PM\n\ mon\n\ @@ -741,6 +757,10 @@ for key in locale_keys: print " " + l['quotationEnd'].encode('utf-8') + "" print " " + l['alternateQuotationStart'].encode('utf-8') + "" print " " + l['alternateQuotationEnd'].encode('utf-8') + "" + print " " + l['listPatternPartStart'].encode('utf-8') + "" + print " " + l['listPatternPartMiddle'].encode('utf-8') + "" + print " " + l['listPatternPartEnd'].encode('utf-8') + "" + print " " + l['listPatternPartTwo'].encode('utf-8') + "" print " " + l['am'].encode('utf-8') + "" print " " + l['pm'].encode('utf-8') + "" print " " + l['firstDayOfWeek'].encode('utf-8') + "" diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index b8e4e896da..e646999fdc 100755 --- a/util/local_database/qlocalexml2cpp.py +++ b/util/local_database/qlocalexml2cpp.py @@ -251,6 +251,10 @@ class Locale: 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"))) @@ -494,6 +498,7 @@ def main(): data_temp_file.write("\n") + list_pattern_part_data = StringData() date_format_data = StringData() time_format_data = StringData() months_data = StringData() @@ -507,7 +512,7 @@ def main(): # Locale data data_temp_file.write("static const QLocalePrivate locale_data[] = {\n") - data_temp_file.write("// lang script terr dec group list prcnt zero minus plus exp quotStart quotEnd altQuotStart altQuotEnd sDtFmt lDtFmt sTmFmt lTmFmt ssMonth slMonth sMonth lMonth sDays lDays am,len pm,len\n") + data_temp_file.write("// lang script terr dec group list prcnt zero minus plus exp quotStart quotEnd altQuotStart altQuotEnd lpStart lpMid lpEnd lpTwo sDtFmt lDtFmt sTmFmt lTmFmt ssMonth slMonth sMonth lMonth sDays lDays am,len pm,len\n") locale_keys = locale_map.keys() compareLocaleKeys.default_map = default_map @@ -516,7 +521,7 @@ def main(): for key in locale_keys: l = locale_map[key] - data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d,%6d,%6d }, // %s/%s/%s\n" \ + data_temp_file.write(" { %6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, {%s}, %s,%s,%s,%s,%6d,%6d,%6d,%6d,%6d }, // %s/%s/%s\n" \ % (key[0], key[1], key[2], l.decimal, l.group, @@ -530,6 +535,10 @@ def main(): l.quotationEnd, l.alternateQuotationStart, l.alternateQuotationEnd, + list_pattern_part_data.append(l.listPatternPartStart), + list_pattern_part_data.append(l.listPatternPartMiddle), + list_pattern_part_data.append(l.listPatternPartEnd), + list_pattern_part_data.append(l.listPatternPartTwo), date_format_data.append(l.shortDateFormat), date_format_data.append(l.longDateFormat), time_format_data.append(l.shortTimeFormat), @@ -561,11 +570,19 @@ def main(): l.language, l.script, l.country)) - data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0, 0, 0 } // trailing 0s\n") + data_temp_file.write(" { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, {0,0,0}, 0,0, 0,0, 0,0, 0,0, 0, 0, 0, 0, 0 } // trailing 0s\n") data_temp_file.write("};\n") data_temp_file.write("\n") + # List patterns data + #check_static_char_array_length("list_pattern_part", list_pattern_part_data.data) + data_temp_file.write("static const ushort list_pattern_part_data[] = {\n") + data_temp_file.write(wrap_list(list_pattern_part_data.data)) + data_temp_file.write("\n};\n") + + data_temp_file.write("\n") + # Date format data #check_static_char_array_length("date_format", date_format_data.data) data_temp_file.write("static const ushort date_format_data[] = {\n") -- cgit v1.2.1