summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@nokia.com>2011-02-15 13:50:20 +0100
committerZeno Albisser <zeno.albisser@nokia.com>2011-02-15 16:58:03 +0100
commit049cc0e6717f684453d40f78e9ec0e9093df2c1d (patch)
tree57c6acce26322e35c36f3e306f8a2581c4d34be0 /util
parent6f313a63d4155b53659917a3f7a71f4de60d0d91 (diff)
downloadqt4-tools-049cc0e6717f684453d40f78e9ec0e9093df2c1d.tar.gz
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
Diffstat (limited to 'util')
-rwxr-xr-xutil/local_database/cldr2qlocalexml.py37
-rwxr-xr-xutil/local_database/qlocalexml2cpp.py10
2 files changed, 45 insertions, 2 deletions
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 <path-to-cldr-main>"
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 \
<exp>101</exp>\n\
<am>AM</am>\n\
<pm>PM</pm>\n\
+ <firstDayOfWeek>mon</firstDayOfWeek>\n\
<longDateFormat>EEEE, d MMMM yyyy</longDateFormat>\n\
<shortDateFormat>d MMM yyyy</shortDateFormat>\n\
<longTimeFormat>HH:mm:ss z</longTimeFormat>\n\
@@ -520,6 +556,7 @@ for key in locale_keys:
print " <exp>" + fixOrdStrExp(l['exp']) + "</exp>"
print " <am>" + l['am'].encode('utf-8') + "</am>"
print " <pm>" + l['pm'].encode('utf-8') + "</pm>"
+ print " <firstDayOfWeek>" + l['firstDayOfWeek'].encode('utf-8') + "</firstDayOfWeek>"
print " <longDateFormat>" + l['longDateFormat'].encode('utf-8') + "</longDateFormat>"
print " <shortDateFormat>" + l['shortDateFormat'].encode('utf-8') + "</shortDateFormat>"
print " <longTimeFormat>" + l['longTimeFormat'].encode('utf-8') + "</longTimeFormat>"
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