diff options
author | Liang Qi <liang.qi@nokia.com> | 2011-03-08 16:32:24 (GMT) |
---|---|---|
committer | Liang Qi <liang.qi@nokia.com> | 2011-03-08 16:32:24 (GMT) |
commit | 09fe2cd62df80373e602d47c570ae317a60a5293 (patch) | |
tree | 494689ed4f7ae7d75d938d851a18f382eb6ef464 /util | |
parent | dc2280dbcd27d3ff9cbcb230943cc1036e8a2761 (diff) | |
download | Qt-09fe2cd62df80373e602d47c570ae317a60a5293.zip Qt-09fe2cd62df80373e602d47c570ae317a60a5293.tar.gz Qt-09fe2cd62df80373e602d47c570ae317a60a5293.tar.bz2 |
Using list patterns to get a string from list in QLocale.
Reviewed-by: Denis Dzyubenko
Task-number: QTBUG-17097
Diffstat (limited to 'util')
-rwxr-xr-x | util/local_database/cldr2qlocalexml.py | 20 | ||||
-rwxr-xr-x | util/local_database/qlocalexml2cpp.py | 23 |
2 files changed, 40 insertions, 3 deletions
diff --git a/util/local_database/cldr2qlocalexml.py b/util/local_database/cldr2qlocalexml.py index fb0e5db..a67971b 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 \ <quotationEnd>\"</quotationEnd>\n\ <alternateQuotationStart>\'</alternateQuotationStart>\n\ <alternateQuotationEnd>\'</alternateQuotationEnd>\n\ + <listPatternPartStart>%1, %2</listPatternPartStart>\n\ + <listPatternPartMiddle>%1, %2</listPatternPartMiddle>\n\ + <listPatternPartEnd>%1, %2</listPatternPartEnd>\n\ + <listPatternPartTwo>%1, %2</listPatternPartTwo>\n\ <am>AM</am>\n\ <pm>PM</pm>\n\ <firstDayOfWeek>mon</firstDayOfWeek>\n\ @@ -741,6 +757,10 @@ for key in locale_keys: print " <quotationEnd>" + l['quotationEnd'].encode('utf-8') + "</quotationEnd>" print " <alternateQuotationStart>" + l['alternateQuotationStart'].encode('utf-8') + "</alternateQuotationStart>" print " <alternateQuotationEnd>" + l['alternateQuotationEnd'].encode('utf-8') + "</alternateQuotationEnd>" + print " <listPatternPartStart>" + l['listPatternPartStart'].encode('utf-8') + "</listPatternPartStart>" + print " <listPatternPartMiddle>" + l['listPatternPartMiddle'].encode('utf-8') + "</listPatternPartMiddle>" + print " <listPatternPartEnd>" + l['listPatternPartEnd'].encode('utf-8') + "</listPatternPartEnd>" + print " <listPatternPartTwo>" + l['listPatternPartTwo'].encode('utf-8') + "</listPatternPartTwo>" print " <am>" + l['am'].encode('utf-8') + "</am>" print " <pm>" + l['pm'].encode('utf-8') + "</pm>" print " <firstDayOfWeek>" + l['firstDayOfWeek'].encode('utf-8') + "</firstDayOfWeek>" diff --git a/util/local_database/qlocalexml2cpp.py b/util/local_database/qlocalexml2cpp.py index b8e4e89..e646999 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") |