2 #############################################################################
4 ## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ## All rights reserved.
6 ## Contact: Nokia Corporation (qt-info@nokia.com)
8 ## This file is part of the test suite of the Qt Toolkit.
10 ## $QT_BEGIN_LICENSE:LGPL$
11 ## GNU Lesser General Public License Usage
12 ## This file may be used under the terms of the GNU Lesser General Public
13 ## License version 2.1 as published by the Free Software Foundation and
14 ## appearing in the file LICENSE.LGPL included in the packaging of this
15 ## file. Please review the following information to ensure the GNU Lesser
16 ## General Public License version 2.1 requirements will be met:
17 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ## In addition, as a special exception, Nokia gives you certain additional
20 ## rights. These rights are described in the Nokia Qt LGPL Exception
21 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ## GNU General Public License Usage
24 ## Alternatively, this file may be used under the terms of the GNU General
25 ## Public License version 3.0 as published by the Free Software Foundation
26 ## and appearing in the file LICENSE.GPL included in the packaging of this
27 ## file. Please review the following information to ensure the GNU General
28 ## Public License version 3.0 requirements will be met:
29 ## http://www.gnu.org/copyleft/gpl.html.
32 ## Alternatively, this file may be used in accordance with the terms and
33 ## conditions contained in a signed written agreement between you and Nokia.
41 #############################################################################
47 import xml.dom.minidom
50 def __init__(self, msg):
55 def check_static_char_array_length(name, array):
56 # some compilers like VC6 doesn't allow static arrays more than 64K bytes size.
57 size = reduce(lambda x, y: x+len(escapedString(y)), array, 0)
59 print "\n\n\n#error Array %s is too long! " % name
60 sys.stderr.write("\n\n\nERROR: the content of the array '%s' is too long: %d > 65535 " % (name, size))
65 for i in range(len(lst)/size+1):
66 yield lst[i*size:(i+1)*size]
67 return ",\n".join(map(lambda x: ", ".join(x), split(lst, 20)))
69 def firstChildElt(parent, name):
70 child = parent.firstChild
72 if child.nodeType == parent.ELEMENT_NODE \
73 and (not name or child.nodeName == name):
75 child = child.nextSibling
78 def nextSiblingElt(sibling, name):
79 sib = sibling.nextSibling
81 if sib.nodeType == sibling.ELEMENT_NODE \
82 and (not name or sib.nodeName == name):
89 child = elt.firstChild
91 if child.nodeType == elt.TEXT_NODE:
94 result += child.nodeValue
95 child = child.nextSibling
98 def loadLanguageMap(doc):
101 language_list_elt = firstChildElt(doc.documentElement, "languageList")
102 language_elt = firstChildElt(language_list_elt, "language")
104 language_id = int(eltText(firstChildElt(language_elt, "id")))
105 language_name = eltText(firstChildElt(language_elt, "name"))
106 language_code = eltText(firstChildElt(language_elt, "code"))
107 result[language_id] = (language_name, language_code)
108 language_elt = nextSiblingElt(language_elt, "language")
112 def loadScriptMap(doc):
115 script_list_elt = firstChildElt(doc.documentElement, "scriptList")
116 script_elt = firstChildElt(script_list_elt, "script")
118 script_id = int(eltText(firstChildElt(script_elt, "id")))
119 script_name = eltText(firstChildElt(script_elt, "name"))
120 script_code = eltText(firstChildElt(script_elt, "code"))
121 result[script_id] = (script_name, script_code)
122 script_elt = nextSiblingElt(script_elt, "script")
126 def loadCountryMap(doc):
129 country_list_elt = firstChildElt(doc.documentElement, "countryList")
130 country_elt = firstChildElt(country_list_elt, "country")
132 country_id = int(eltText(firstChildElt(country_elt, "id")))
133 country_name = eltText(firstChildElt(country_elt, "name"))
134 country_code = eltText(firstChildElt(country_elt, "code"))
135 result[country_id] = (country_name, country_code)
136 country_elt = nextSiblingElt(country_elt, "country")
140 def loadDefaultMap(doc):
143 list_elt = firstChildElt(doc.documentElement, "defaultCountryList")
144 elt = firstChildElt(list_elt, "defaultCountry")
146 country = eltText(firstChildElt(elt, "country"));
147 language = eltText(firstChildElt(elt, "language"));
148 result[language] = country;
149 elt = nextSiblingElt(elt, "defaultCountry");
152 def fixedScriptName(name, dupes):
153 name = name.replace(" ", "")
154 if name[-6:] != "Script":
155 name = name + "Script";
157 sys.stderr.write("\n\n\nERROR: The script name '%s' is messy" % name)
161 def fixedCountryName(name, dupes):
163 return name.replace(" ", "") + "Country"
164 return name.replace(" ", "")
166 def fixedLanguageName(name, dupes):
168 return name.replace(" ", "") + "Language"
169 return name.replace(" ", "")
171 def findDupes(country_map, language_map):
172 country_set = set([ v[0] for a, v in country_map.iteritems() ])
173 language_set = set([ v[0] for a, v in language_map.iteritems() ])
174 return country_set & language_set
176 def languageNameToId(name, language_map):
177 for key in language_map.keys():
178 if language_map[key][0] == name:
182 def scriptNameToId(name, script_map):
183 for key in script_map.keys():
184 if script_map[key][0] == name:
188 def countryNameToId(name, country_map):
189 for key in country_map.keys():
190 if country_map[key][0] == name:
194 def convertFormat(format):
197 while i < len(format):
201 while i < len(format) and format[i] != "'":
209 if s.startswith("EEEE"):
212 elif s.startswith("EEE"):
215 elif s.startswith("a"):
218 elif s.startswith("z"):
221 elif s.startswith("v"):
229 def convertToQtDayOfWeek(firstDay):
230 qtDayOfWeek = {"mon":1, "tue":2, "wed":3, "thu":4, "fri":5, "sat":6, "sun":7}
231 return qtDayOfWeek[firstDay]
233 def assertSingleChar(string):
234 assert len(string) == 1, "This string is not allowed to be longer than 1 character"
238 def __init__(self, elt):
239 self.language = eltText(firstChildElt(elt, "language"))
240 self.languageEndonym = eltText(firstChildElt(elt, "languageEndonym"))
241 self.script = eltText(firstChildElt(elt, "script"))
242 self.country = eltText(firstChildElt(elt, "country"))
243 self.countryEndonym = eltText(firstChildElt(elt, "countryEndonym"))
244 self.decimal = int(eltText(firstChildElt(elt, "decimal")))
245 self.group = int(eltText(firstChildElt(elt, "group")))
246 self.listDelim = int(eltText(firstChildElt(elt, "list")))
247 self.percent = int(eltText(firstChildElt(elt, "percent")))
248 self.zero = int(eltText(firstChildElt(elt, "zero")))
249 self.minus = int(eltText(firstChildElt(elt, "minus")))
250 self.plus = int(eltText(firstChildElt(elt, "plus")))
251 self.exp = int(eltText(firstChildElt(elt, "exp")))
252 self.quotationStart = ord(assertSingleChar(eltText(firstChildElt(elt, "quotationStart"))))
253 self.quotationEnd = ord(assertSingleChar(eltText(firstChildElt(elt, "quotationEnd"))))
254 self.alternateQuotationStart = ord(assertSingleChar(eltText(firstChildElt(elt, "alternateQuotationStart"))))
255 self.alternateQuotationEnd = ord(assertSingleChar(eltText(firstChildElt(elt, "alternateQuotationEnd"))))
256 self.listPatternPartStart = eltText(firstChildElt(elt, "listPatternPartStart"))
257 self.listPatternPartMiddle = eltText(firstChildElt(elt, "listPatternPartMiddle"))
258 self.listPatternPartEnd = eltText(firstChildElt(elt, "listPatternPartEnd"))
259 self.listPatternPartTwo = eltText(firstChildElt(elt, "listPatternPartTwo"))
260 self.am = eltText(firstChildElt(elt, "am"))
261 self.pm = eltText(firstChildElt(elt, "pm"))
262 self.firstDayOfWeek = convertToQtDayOfWeek(eltText(firstChildElt(elt, "firstDayOfWeek")))
263 self.weekendStart = convertToQtDayOfWeek(eltText(firstChildElt(elt, "weekendStart")))
264 self.weekendEnd = convertToQtDayOfWeek(eltText(firstChildElt(elt, "weekendEnd")))
265 self.longDateFormat = convertFormat(eltText(firstChildElt(elt, "longDateFormat")))
266 self.shortDateFormat = convertFormat(eltText(firstChildElt(elt, "shortDateFormat")))
267 self.longTimeFormat = convertFormat(eltText(firstChildElt(elt, "longTimeFormat")))
268 self.shortTimeFormat = convertFormat(eltText(firstChildElt(elt, "shortTimeFormat")))
269 self.standaloneLongMonths = eltText(firstChildElt(elt, "standaloneLongMonths"))
270 self.standaloneShortMonths = eltText(firstChildElt(elt, "standaloneShortMonths"))
271 self.standaloneNarrowMonths = eltText(firstChildElt(elt, "standaloneNarrowMonths"))
272 self.longMonths = eltText(firstChildElt(elt, "longMonths"))
273 self.shortMonths = eltText(firstChildElt(elt, "shortMonths"))
274 self.narrowMonths = eltText(firstChildElt(elt, "narrowMonths"))
275 self.standaloneLongDays = eltText(firstChildElt(elt, "standaloneLongDays"))
276 self.standaloneShortDays = eltText(firstChildElt(elt, "standaloneShortDays"))
277 self.standaloneNarrowDays = eltText(firstChildElt(elt, "standaloneNarrowDays"))
278 self.longDays = eltText(firstChildElt(elt, "longDays"))
279 self.shortDays = eltText(firstChildElt(elt, "shortDays"))
280 self.narrowDays = eltText(firstChildElt(elt, "narrowDays"))
281 self.currencyIsoCode = eltText(firstChildElt(elt, "currencyIsoCode"))
282 self.currencySymbol = eltText(firstChildElt(elt, "currencySymbol"))
283 self.currencyDisplayName = eltText(firstChildElt(elt, "currencyDisplayName"))
284 self.currencyDigits = int(eltText(firstChildElt(elt, "currencyDigits")))
285 self.currencyRounding = int(eltText(firstChildElt(elt, "currencyRounding")))
286 self.currencyFormat = eltText(firstChildElt(elt, "currencyFormat"))
287 self.currencyNegativeFormat = eltText(firstChildElt(elt, "currencyNegativeFormat"))
289 def loadLocaleMap(doc, language_map, script_map, country_map):
292 locale_list_elt = firstChildElt(doc.documentElement, "localeList")
293 locale_elt = firstChildElt(locale_list_elt, "locale")
295 locale = Locale(locale_elt)
296 language_id = languageNameToId(locale.language, language_map)
297 if language_id == -1:
298 sys.stderr.write("Cannot find a language id for '%s'\n" % locale.language)
299 script_id = scriptNameToId(locale.script, script_map)
301 sys.stderr.write("Cannot find a script id for '%s'\n" % locale.script)
302 country_id = countryNameToId(locale.country, country_map)
304 sys.stderr.write("Cannot find a country id for '%s'\n" % locale.country)
305 result[(language_id, script_id, country_id)] = locale
307 locale_elt = nextSiblingElt(locale_elt, "locale")
311 def compareLocaleKeys(key1, key2):
315 if key1[0] == key2[0]:
316 l1 = compareLocaleKeys.locale_map[key1]
317 l2 = compareLocaleKeys.locale_map[key2]
319 if l1.language in compareLocaleKeys.default_map:
320 default = compareLocaleKeys.default_map[l1.language]
321 if l1.country == default and key1[1] == 0:
323 if l2.country == default and key2[1] == 0:
326 if key1[1] != key2[1]:
327 return key1[1] - key2[1]
329 return key1[0] - key2[0]
331 return key1[2] - key2[2]
334 def languageCount(language_id, locale_map):
336 for key in locale_map.keys():
337 if key[0] == language_id:
346 # make a surrogate pair
347 # copied from qchar.h
348 high = (v >> 10) + 0xd7c0
349 low = (v % 0x400 + 0xdc00)
350 lst.append(hex(high))
356 class StringDataToken:
357 def __init__(self, index, length):
358 if index > 0xFFFF or length > 0xFFFF:
359 raise Error("Position exceeds ushort range: %d,%d " % (index, length))
363 return " %d,%d " % (self.index, self.length)
374 index = len(self.data)
376 print "\n\n\n#error Data index is too big!"
377 sys.stderr.write ("\n\n\nERROR: index exceeds the uint16 range! index = %d\n" % index)
381 print "\n\n\n#error Data is too big!"
382 sys.stderr.write ("\n\n\nERROR: data size exceeds the uint16 range! size = %d\n" % size)
386 token = StringDataToken(index, size)
388 sys.stderr.write("\n\n\nERROR: %s: on data '%s'" % (e, s))
394 def escapedString(s):
410 if ord(c) < 128 and (not need_escape or ord(c.lower()) < ord('a') or ord(c.lower()) > ord('f')):
414 line += "\\x%02x" % (ord(c))
417 result = result + "\n" + "\"" + line + "\""
420 result = result + "\n" + "\"" + line + "\""
421 if result[0] == "\n":
425 def printEscapedString(s):
426 print escapedString(s);
429 def currencyIsoCodeData(s):
431 return ",".join(map(lambda x: str(ord(x)), s))
435 print "Usage: qlocalexml2cpp.py <path-to-locale.xml> <path-to-qt-src-tree>"
438 GENERATED_BLOCK_START = "// GENERATED PART STARTS HERE\n"
439 GENERATED_BLOCK_END = "// GENERATED PART ENDS HERE\n"
442 if len(sys.argv) != 3:
445 localexml = sys.argv[1]
446 qtsrcdir = sys.argv[2]
448 if not os.path.exists(qtsrcdir) or not os.path.exists(qtsrcdir):
450 if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale_data_p.h"):
452 if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.h"):
454 if not os.path.isfile(qtsrcdir + "/src/corelib/tools/qlocale.qdoc"):
457 (data_temp_file, data_temp_file_path) = tempfile.mkstemp("qlocale_data_p", dir=qtsrcdir)
458 data_temp_file = os.fdopen(data_temp_file, "w")
459 qlocaledata_file = open(qtsrcdir + "/src/corelib/tools/qlocale_data_p.h", "r")
460 s = qlocaledata_file.readline()
461 while s and s != GENERATED_BLOCK_START:
462 data_temp_file.write(s)
463 s = qlocaledata_file.readline()
464 data_temp_file.write(GENERATED_BLOCK_START)
466 doc = xml.dom.minidom.parse(localexml)
467 language_map = loadLanguageMap(doc)
468 script_map = loadScriptMap(doc)
469 country_map = loadCountryMap(doc)
470 default_map = loadDefaultMap(doc)
471 locale_map = loadLocaleMap(doc, language_map, script_map, country_map)
472 dupes = findDupes(language_map, country_map)
474 cldr_version = eltText(firstChildElt(doc.documentElement, "version"))
476 data_temp_file.write("\n\
478 This part of the file was generated on %s from the\n\
479 Common Locale Data Repository v%s\n\
481 http://www.unicode.org/cldr/\n\
483 Do not change it, instead edit CLDR data and regenerate this file using\n\
484 cldr2qlocalexml.py and qlocalexml2cpp.py.\n\
486 " % (str(datetime.date.today()), cldr_version) )
489 data_temp_file.write("static const quint16 locale_index[] = {\n")
491 for key in language_map.keys():
493 count = languageCount(key, locale_map)
497 data_temp_file.write("%6d, // %s\n" % (i, language_map[key][0]))
498 data_temp_file.write(" 0 // trailing 0\n")
499 data_temp_file.write("};\n")
501 data_temp_file.write("\n")
503 list_pattern_part_data = StringData()
504 date_format_data = StringData()
505 time_format_data = StringData()
506 months_data = StringData()
507 standalone_months_data = StringData()
508 days_data = StringData()
509 am_data = StringData()
510 pm_data = StringData()
511 currency_symbol_data = StringData()
512 currency_display_name_data = StringData()
513 currency_format_data = StringData()
514 endonyms_data = StringData()
517 data_temp_file.write("static const QLocalePrivate locale_data[] = {\n")
518 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")
520 locale_keys = locale_map.keys()
521 compareLocaleKeys.default_map = default_map
522 compareLocaleKeys.locale_map = locale_map
523 locale_keys.sort(compareLocaleKeys)
525 for key in locale_keys:
527 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,%s,%s,%6d,%6d,%6d,%6d,%6d }, // %s/%s/%s\n" \
528 % (key[0], key[1], key[2],
539 l.alternateQuotationStart,
540 l.alternateQuotationEnd,
541 list_pattern_part_data.append(l.listPatternPartStart),
542 list_pattern_part_data.append(l.listPatternPartMiddle),
543 list_pattern_part_data.append(l.listPatternPartEnd),
544 list_pattern_part_data.append(l.listPatternPartTwo),
545 date_format_data.append(l.shortDateFormat),
546 date_format_data.append(l.longDateFormat),
547 time_format_data.append(l.shortTimeFormat),
548 time_format_data.append(l.longTimeFormat),
549 standalone_months_data.append(l.standaloneShortMonths),
550 standalone_months_data.append(l.standaloneLongMonths),
551 standalone_months_data.append(l.standaloneNarrowMonths),
552 months_data.append(l.shortMonths),
553 months_data.append(l.longMonths),
554 months_data.append(l.narrowMonths),
555 days_data.append(l.standaloneShortDays),
556 days_data.append(l.standaloneLongDays),
557 days_data.append(l.standaloneNarrowDays),
558 days_data.append(l.shortDays),
559 days_data.append(l.longDays),
560 days_data.append(l.narrowDays),
561 am_data.append(l.am),
562 pm_data.append(l.pm),
563 currencyIsoCodeData(l.currencyIsoCode),
564 currency_symbol_data.append(l.currencySymbol),
565 currency_display_name_data.append(l.currencyDisplayName),
566 currency_format_data.append(l.currencyFormat),
567 currency_format_data.append(l.currencyNegativeFormat),
568 endonyms_data.append(l.languageEndonym),
569 endonyms_data.append(l.countryEndonym),
578 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, 0,0, 0,0 } // trailing 0s\n")
579 data_temp_file.write("};\n")
581 data_temp_file.write("\n")
584 #check_static_char_array_length("list_pattern_part", list_pattern_part_data.data)
585 data_temp_file.write("static const ushort list_pattern_part_data[] = {\n")
586 data_temp_file.write(wrap_list(list_pattern_part_data.data))
587 data_temp_file.write("\n};\n")
589 data_temp_file.write("\n")
592 #check_static_char_array_length("date_format", date_format_data.data)
593 data_temp_file.write("static const ushort date_format_data[] = {\n")
594 data_temp_file.write(wrap_list(date_format_data.data))
595 data_temp_file.write("\n};\n")
597 data_temp_file.write("\n")
600 #check_static_char_array_length("time_format", time_format_data.data)
601 data_temp_file.write("static const ushort time_format_data[] = {\n")
602 data_temp_file.write(wrap_list(time_format_data.data))
603 data_temp_file.write("\n};\n")
605 data_temp_file.write("\n")
608 #check_static_char_array_length("months", months_data.data)
609 data_temp_file.write("static const ushort months_data[] = {\n")
610 data_temp_file.write(wrap_list(months_data.data))
611 data_temp_file.write("\n};\n")
613 data_temp_file.write("\n")
615 # Standalone months data
616 #check_static_char_array_length("standalone_months", standalone_months_data.data)
617 data_temp_file.write("static const ushort standalone_months_data[] = {\n")
618 data_temp_file.write(wrap_list(standalone_months_data.data))
619 data_temp_file.write("\n};\n")
621 data_temp_file.write("\n")
624 #check_static_char_array_length("days", days_data.data)
625 data_temp_file.write("static const ushort days_data[] = {\n")
626 data_temp_file.write(wrap_list(days_data.data))
627 data_temp_file.write("\n};\n")
629 data_temp_file.write("\n")
632 #check_static_char_array_length("am", am_data.data)
633 data_temp_file.write("static const ushort am_data[] = {\n")
634 data_temp_file.write(wrap_list(am_data.data))
635 data_temp_file.write("\n};\n")
637 data_temp_file.write("\n")
640 #check_static_char_array_length("pm", am_data.data)
641 data_temp_file.write("static const ushort pm_data[] = {\n")
642 data_temp_file.write(wrap_list(pm_data.data))
643 data_temp_file.write("\n};\n")
645 data_temp_file.write("\n")
647 # Currency symbol data
648 #check_static_char_array_length("currency_symbol", currency_symbol_data.data)
649 data_temp_file.write("static const ushort currency_symbol_data[] = {\n")
650 data_temp_file.write(wrap_list(currency_symbol_data.data))
651 data_temp_file.write("\n};\n")
653 data_temp_file.write("\n")
655 # Currency display name data
656 #check_static_char_array_length("currency_display_name", currency_display_name_data.data)
657 data_temp_file.write("static const ushort currency_display_name_data[] = {\n")
658 data_temp_file.write(wrap_list(currency_display_name_data.data))
659 data_temp_file.write("\n};\n")
661 data_temp_file.write("\n")
663 # Currency format data
664 #check_static_char_array_length("currency_format", currency_format_data.data)
665 data_temp_file.write("static const ushort currency_format_data[] = {\n")
666 data_temp_file.write(wrap_list(currency_format_data.data))
667 data_temp_file.write("\n};\n")
670 #check_static_char_array_length("endonyms", endonyms_data.data)
671 data_temp_file.write("static const ushort endonyms_data[] = {\n")
672 data_temp_file.write(wrap_list(endonyms_data.data))
673 data_temp_file.write("\n};\n")
675 data_temp_file.write("\n")
678 data_temp_file.write("static const char language_name_list[] =\n")
679 data_temp_file.write("\"Default\\0\"\n")
680 for key in language_map.keys():
683 data_temp_file.write("\"" + language_map[key][0] + "\\0\"\n")
684 data_temp_file.write(";\n")
686 data_temp_file.write("\n")
688 # Language name index
689 data_temp_file.write("static const quint16 language_name_index[] = {\n")
690 data_temp_file.write(" 0, // AnyLanguage\n")
692 for key in language_map.keys():
695 language = language_map[key][0]
696 data_temp_file.write("%6d, // %s\n" % (index, language))
697 index += len(language) + 1
698 data_temp_file.write("};\n")
700 data_temp_file.write("\n")
703 data_temp_file.write("static const char script_name_list[] =\n")
704 data_temp_file.write("\"Default\\0\"\n")
705 for key in script_map.keys():
708 data_temp_file.write("\"" + script_map[key][0] + "\\0\"\n")
709 data_temp_file.write(";\n")
711 data_temp_file.write("\n")
714 data_temp_file.write("static const quint16 script_name_index[] = {\n")
715 data_temp_file.write(" 0, // AnyScript\n")
717 for key in script_map.keys():
720 script = script_map[key][0]
721 data_temp_file.write("%6d, // %s\n" % (index, script))
722 index += len(script) + 1
723 data_temp_file.write("};\n")
725 data_temp_file.write("\n")
728 data_temp_file.write("static const char country_name_list[] =\n")
729 data_temp_file.write("\"Default\\0\"\n")
730 for key in country_map.keys():
733 data_temp_file.write("\"" + country_map[key][0] + "\\0\"\n")
734 data_temp_file.write(";\n")
736 data_temp_file.write("\n")
739 data_temp_file.write("static const quint16 country_name_index[] = {\n")
740 data_temp_file.write(" 0, // AnyCountry\n")
742 for key in country_map.keys():
745 country = country_map[key][0]
746 data_temp_file.write("%6d, // %s\n" % (index, country))
747 index += len(country) + 1
748 data_temp_file.write("};\n")
750 data_temp_file.write("\n")
753 data_temp_file.write("static const unsigned char language_code_list[] =\n")
754 for key in language_map.keys():
755 code = language_map[key][1]
758 data_temp_file.write("\"%2s\" // %s\n" % (code, language_map[key][0]))
759 data_temp_file.write(";\n")
761 data_temp_file.write("\n")
764 data_temp_file.write("static const unsigned char script_code_list[] =\n")
765 for key in script_map.keys():
766 code = script_map[key][1]
767 for i in range(4 - len(code)):
769 data_temp_file.write("\"%2s\" // %s\n" % (code, script_map[key][0]))
770 data_temp_file.write(";\n")
773 data_temp_file.write("static const unsigned char country_code_list[] =\n")
774 for key in country_map.keys():
775 code = country_map[key][1]
778 data_temp_file.write("\"%2s\" // %s\n" % (code, country_map[key][0]))
779 data_temp_file.write(";\n")
781 data_temp_file.write("\n")
782 data_temp_file.write(GENERATED_BLOCK_END)
783 s = qlocaledata_file.readline()
784 # skip until end of the block
785 while s and s != GENERATED_BLOCK_END:
786 s = qlocaledata_file.readline()
788 s = qlocaledata_file.readline()
790 data_temp_file.write(s)
791 s = qlocaledata_file.readline()
792 data_temp_file.close()
793 qlocaledata_file.close()
795 os.rename(data_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale_data_p.h")
799 (qlocaleh_temp_file, qlocaleh_temp_file_path) = tempfile.mkstemp("qlocale.h", dir=qtsrcdir)
800 qlocaleh_temp_file = os.fdopen(qlocaleh_temp_file, "w")
801 qlocaleh_file = open(qtsrcdir + "/src/corelib/tools/qlocale.h", "r")
802 s = qlocaleh_file.readline()
803 while s and s != GENERATED_BLOCK_START:
804 qlocaleh_temp_file.write(s)
805 s = qlocaleh_file.readline()
806 qlocaleh_temp_file.write(GENERATED_BLOCK_START)
807 qlocaleh_temp_file.write("// see qlocale_data_p.h for more info on generated data\n")
810 qlocaleh_temp_file.write(" enum Language {\n")
812 for key in language_map.keys():
813 language = fixedLanguageName(language_map[key][0], dupes)
814 qlocaleh_temp_file.write(" " + language + " = " + str(key) + ",\n")
815 # special cases for norwegian. we really need to make it right at some point.
816 qlocaleh_temp_file.write(" NorwegianBokmal = Norwegian,\n")
817 qlocaleh_temp_file.write(" NorwegianNynorsk = Nynorsk,\n")
818 qlocaleh_temp_file.write(" LastLanguage = " + language + "\n")
819 qlocaleh_temp_file.write(" };\n")
821 qlocaleh_temp_file.write("\n")
824 qlocaleh_temp_file.write(" enum Script {\n")
826 for key in script_map.keys():
827 script = fixedScriptName(script_map[key][0], dupes)
828 qlocaleh_temp_file.write(" " + script + " = " + str(key) + ",\n")
829 qlocaleh_temp_file.write(" SimplifiedChineseScript = SimplifiedHanScript,\n")
830 qlocaleh_temp_file.write(" TraditionalChineseScript = TraditionalHanScript,\n")
831 qlocaleh_temp_file.write(" LastScript = " + script + "\n")
832 qlocaleh_temp_file.write(" };\n")
835 qlocaleh_temp_file.write(" enum Country {\n")
837 for key in country_map.keys():
838 country = fixedCountryName(country_map[key][0], dupes)
839 qlocaleh_temp_file.write(" " + country + " = " + str(key) + ",\n")
840 qlocaleh_temp_file.write(" LastCountry = " + country + "\n")
841 qlocaleh_temp_file.write(" };\n")
843 qlocaleh_temp_file.write(GENERATED_BLOCK_END)
844 s = qlocaleh_file.readline()
845 # skip until end of the block
846 while s and s != GENERATED_BLOCK_END:
847 s = qlocaleh_file.readline()
849 s = qlocaleh_file.readline()
851 qlocaleh_temp_file.write(s)
852 s = qlocaleh_file.readline()
853 qlocaleh_temp_file.close()
854 qlocaleh_file.close()
856 os.rename(qlocaleh_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.h")
860 (qlocaleqdoc_temp_file, qlocaleqdoc_temp_file_path) = tempfile.mkstemp("qlocale.qdoc", dir=qtsrcdir)
861 qlocaleqdoc_temp_file = os.fdopen(qlocaleqdoc_temp_file, "w")
862 qlocaleqdoc_file = open(qtsrcdir + "/src/corelib/tools/qlocale.qdoc", "r")
863 s = qlocaleqdoc_file.readline()
864 DOCSTRING=" QLocale's data is based on Common Locale Data Repository "
867 qlocaleqdoc_temp_file.write(DOCSTRING + "v" + cldr_version + ".\n")
869 qlocaleqdoc_temp_file.write(s)
870 s = qlocaleqdoc_file.readline()
871 qlocaleqdoc_temp_file.close()
872 qlocaleqdoc_file.close()
874 os.rename(qlocaleqdoc_temp_file_path, qtsrcdir + "/src/corelib/tools/qlocale.qdoc")
876 if __name__ == "__main__":