Tidy up generation of aliases in locale-related enums

Replace lines of formatted output with dictionaries from which that
output can be generated efficiently (in sorted order).  Tidy up the
python code, in the process.

Change-Id: Ifb74eb69342646c5dbabc3247b3a8ddef602e934
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2018-08-13 14:32:18 +02:00
parent d363113745
commit cd0a76a150
3 changed files with 83 additions and 59 deletions

View File

@ -437,19 +437,19 @@ public:
Osage = 358,
Tangut = 359,
Norwegian = NorwegianBokmal,
Afan = Oromo,
Bhutani = Dzongkha,
Byelorussian = Belarusian,
Cambodian = Khmer,
Chewa = Nyanja,
Frisian = WesternFrisian,
Kurundi = Rundi,
Moldavian = Romanian,
Norwegian = NorwegianBokmal,
RhaetoRomance = Romansh,
SerboCroatian = Serbian,
Tagalog = Filipino,
Twi = Akan,
Afan = Oromo,
Byelorussian = Belarusian,
Bhutani = Dzongkha,
Cambodian = Khmer,
Kurundi = Rundi,
RhaetoRomance = Romansh,
Chewa = Nyanja,
Frisian = WesternFrisian,
Uigur = Uighur,
LastLanguage = Tangut
@ -868,15 +868,15 @@ public:
World = 260,
Europe = 261,
Tokelau = TokelauCountry,
Tuvalu = TuvaluCountry,
DemocraticRepublicOfCongo = CongoKinshasa,
PeoplesRepublicOfCongo = CongoBrazzaville,
DemocraticRepublicOfKorea = NorthKorea,
LatinAmericaAndTheCaribbean = LatinAmerica,
PeoplesRepublicOfCongo = CongoBrazzaville,
RepublicOfKorea = SouthKorea,
RussianFederation = Russia,
SyrianArabRepublic = Syria,
LatinAmericaAndTheCaribbean = LatinAmerica,
Tokelau = TokelauCountry,
Tuvalu = TuvaluCountry,
LastCountry = Europe
};

View File

@ -27,9 +27,13 @@
##
#############################################################################
# language_list and country_list reflect the current values of enums in qlocale.h
# If new xml language files are available in CLDR, these languages and countries
# need to be *appended* to this list (for compatibility between versions).
# Each *_list reflects the current values of its enums in qlocale.h;
# if new xml language files are available in CLDR, these languages and
# countries need to be *appended* to this list (for compatibility
# between versions). Include any spaces present in names (scripts
# shall squish them out for the enum entries) in *_list, but use the
# squished forms of names in the *_aliases mappings.
### Qt 6: restore alphabetic order in each list.
language_list = {
@ -395,6 +399,25 @@ language_list = {
359 : ["Tangut", "txg"]
}
language_aliases = {
# Legacy - should disappear at some point:
'Norwegian': 'NorwegianBokmal',
'Moldavian': 'Romanian',
'SerboCroatian': 'Serbian',
'Tagalog': 'Filipino',
'Twi': 'Akan',
# Renamings:
'Afan': 'Oromo',
'Byelorussian': 'Belarusian',
'Bhutani': 'Dzongkha',
'Cambodian': 'Khmer',
'Kurundi': 'Rundi',
'RhaetoRomance': 'Romansh',
'Chewa': 'Nyanja',
'Frisian': 'WesternFrisian',
'Uigur': 'Uighur',
}
country_list = {
0 : ["AnyCountry", "ZZ"],
1 : ["Afghanistan", "AF"],
@ -660,6 +683,20 @@ country_list = {
261 : ["Europe", "150"]
}
country_aliases = {
# Deprecated:
'Tokelau': 'TokelauCountry',
'Tuvalu': 'TuvaluCountry',
# Renamings:
'DemocraticRepublicOfCongo': 'CongoKinshasa',
'PeoplesRepublicOfCongo': 'CongoBrazzaville',
'DemocraticRepublicOfKorea': 'NorthKorea',
'RepublicOfKorea': 'SouthKorea',
'RussianFederation': 'Russia',
'SyrianArabRepublic': 'Syria',
'LatinAmericaAndTheCaribbean': 'LatinAmerica',
}
script_list = {
0 : ["AnyScript", "Zzzz"],
1 : ["Arabic", "Arab"],
@ -805,6 +842,12 @@ script_list = {
141 : ["Jamo", "Jamo"]
}
script_aliases = {
# Renamings:
'SimplifiedChineseScript': 'SimplifiedHanScript',
'TraditionalChineseScript': 'TraditionalHanScript',
}
def countryCodeToId(code):
if not code:
return 0

View File

@ -38,6 +38,7 @@ import sys
import tempfile
import datetime
import xml.dom.minidom
from enumdata import language_aliases, country_aliases, script_aliases
from localexml import Locale
@ -751,27 +752,15 @@ def main():
# Language enum
qlocaleh_temp_file.write(" enum Language {\n")
language = ""
for key in language_map.keys():
language = fixedLanguageName(language_map[key][0], dupes)
language = None
for key, value in language_map.items():
language = fixedLanguageName(value[0], dupes)
qlocaleh_temp_file.write(" " + language + " = " + str(key) + ",\n")
# legacy. should disappear at some point
qlocaleh_temp_file.write("\n")
qlocaleh_temp_file.write(" Norwegian = NorwegianBokmal,\n")
qlocaleh_temp_file.write(" Moldavian = Romanian,\n")
qlocaleh_temp_file.write(" SerboCroatian = Serbian,\n")
qlocaleh_temp_file.write(" Tagalog = Filipino,\n")
qlocaleh_temp_file.write(" Twi = Akan,\n")
# renamings
qlocaleh_temp_file.write(" Afan = Oromo,\n")
qlocaleh_temp_file.write(" Byelorussian = Belarusian,\n")
qlocaleh_temp_file.write(" Bhutani = Dzongkha,\n")
qlocaleh_temp_file.write(" Cambodian = Khmer,\n")
qlocaleh_temp_file.write(" Kurundi = Rundi,\n")
qlocaleh_temp_file.write(" RhaetoRomance = Romansh,\n")
qlocaleh_temp_file.write(" Chewa = Nyanja,\n")
qlocaleh_temp_file.write(" Frisian = WesternFrisian,\n")
qlocaleh_temp_file.write(" Uigur = Uighur,\n")
qlocaleh_temp_file.write("\n " +
",\n ".join('%s = %s' % pair
for pair in sorted(language_aliases.items())) +
",\n")
qlocaleh_temp_file.write("\n")
qlocaleh_temp_file.write(" LastLanguage = " + language + "\n")
qlocaleh_temp_file.write(" };\n")
@ -780,36 +769,28 @@ def main():
# Script enum
qlocaleh_temp_file.write(" enum Script {\n")
script = ""
for key in script_map.keys():
script = fixedScriptName(script_map[key][0], dupes)
script = None
for key, value in script_map.items():
script = fixedScriptName(value[0], dupes)
qlocaleh_temp_file.write(" " + script + " = " + str(key) + ",\n")
# renamings
qlocaleh_temp_file.write("\n")
qlocaleh_temp_file.write(" SimplifiedChineseScript = SimplifiedHanScript,\n")
qlocaleh_temp_file.write(" TraditionalChineseScript = TraditionalHanScript,\n")
qlocaleh_temp_file.write("\n " +
",\n ".join('%s = %s' % pair
for pair in sorted(script_aliases.items())) +
",\n")
qlocaleh_temp_file.write("\n")
qlocaleh_temp_file.write(" LastScript = " + script + "\n")
qlocaleh_temp_file.write(" };\n")
# Country enum
qlocaleh_temp_file.write(" enum Country {\n")
country = ""
for key in country_map.keys():
country = fixedCountryName(country_map[key][0], dupes)
country = None
for key, value in country_map.items():
country = fixedCountryName(value[0], dupes)
qlocaleh_temp_file.write(" " + country + " = " + str(key) + ",\n")
# deprecated
qlocaleh_temp_file.write("\n")
qlocaleh_temp_file.write(" Tokelau = TokelauCountry,\n")
qlocaleh_temp_file.write(" Tuvalu = TuvaluCountry,\n")
# renamings
qlocaleh_temp_file.write(" DemocraticRepublicOfCongo = CongoKinshasa,\n")
qlocaleh_temp_file.write(" PeoplesRepublicOfCongo = CongoBrazzaville,\n")
qlocaleh_temp_file.write(" DemocraticRepublicOfKorea = NorthKorea,\n")
qlocaleh_temp_file.write(" RepublicOfKorea = SouthKorea,\n")
qlocaleh_temp_file.write(" RussianFederation = Russia,\n")
qlocaleh_temp_file.write(" SyrianArabRepublic = Syria,\n")
qlocaleh_temp_file.write(" LatinAmericaAndTheCaribbean = LatinAmerica,\n")
qlocaleh_temp_file.write("\n " +
",\n ".join('%s = %s' % pair
for pair in sorted(country_aliases.items())) +
",\n")
qlocaleh_temp_file.write("\n")
qlocaleh_temp_file.write(" LastCountry = " + country + "\n")
qlocaleh_temp_file.write(" };\n")
@ -836,7 +817,7 @@ def main():
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 "
DOCSTRING = " QLocale's data is based on Common Locale Data Repository "
while s:
if DOCSTRING in s:
qlocaleqdoc_temp_file.write(DOCSTRING + "v" + cldr_version + ".\n")