map duplicate language, script and country codes as aliases

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2019-08-07 14:48:16 +00:00
parent 9ce34c18eb
commit b8487a6cb0
3 changed files with 990 additions and 981 deletions

View file

@ -215,13 +215,22 @@ def normalizestring(fromstring):
result = result.replace(u'í', 'i')
return result
# printenum prints mapped values that have unique code only, the rest are set to the enum of the
# first occurence. the reason for doing so is because table lookups for figuring out language,
# script and country that is required for constructing QLocale from string (named locales) relies
# on the fact that there is only one code for each, if that is not the case constructing copy of
# locale from its name will not copy it correctly. printtable skips duplicate code entries entirely
def printenum(frommap, prefix):
keyscount = 0
aliaseslist = []
seenfirstvalues = []
print(' enum %s {' % prefix)
# print Default and C first
for key in frommap.keys():
if not key in ('Any%s' % prefix, 'C'):
continue
firstvalue = frommap[key][0]
print(' %s = %d,' % (key, keyscount))
keyscount += 1
@ -230,15 +239,36 @@ def printenum(frommap, prefix):
for key in sorted(frommap.keys()):
if key in ('Any%s' % prefix, 'C'):
continue
firstvalue = frommap[key][0]
if firstvalue in seenfirstvalues:
aliaseslist.append(key)
continue
seenfirstvalues.append(firstvalue)
print(' %s = %d,' % (key, keyscount))
lastkey = key
keyscount += 1
# now aliases
print('')
for alias in sorted(aliaseslist):
firstvalue = frommap[alias][0]
aliasenum = None
for key in sorted(frommap.keys()):
keyfirstvalue = frommap[key][0]
if firstvalue == keyfirstvalue:
aliasenum == key
break
print(' %s = %s,' % (alias, key))
# print last key
print('\n Last%s = %s' % (prefix, lastkey))
print(' };\n')
def printtable(frommap, prefix):
lowerprefix = prefix.lower()
seenfirstvalues = []
print('''static const struct %sTblData {
const char* name;
const char* code;
@ -253,11 +283,14 @@ def printtable(frommap, prefix):
secondvalue = frommap[key][1]
print(' { "%s\\0", "%s\\0", QLocale::%s::%s },' % (secondvalue, firstvalue, prefix, key))
# now everything except those
# now everything except those but only unique code values
for key in sorted(frommap.keys()):
if key in ('Any%s' % prefix, 'C'):
continue
firstvalue = frommap[key][0]
if firstvalue in seenfirstvalues:
continue
seenfirstvalues.append(firstvalue)
secondvalue = frommap[key][1]
print(' { "%s\\0", "%s\\0", QLocale::%s::%s },' % (secondvalue, firstvalue, prefix, key))

File diff suppressed because it is too large Load diff

View file

@ -108,7 +108,6 @@ static const struct languageTblData {
{ "Awadhi\0", "awa\0", QLocale::Language::Awadhi },
{ "Aymara\0", "ay\0", QLocale::Language::Aymara },
{ "Azerbaijani\0", "az\0", QLocale::Language::Azerbaijani },
{ "Azeri\0", "az\0", QLocale::Language::Azeri },
{ "Badaga\0", "bfq\0", QLocale::Language::Badaga },
{ "Bafia\0", "ksf\0", QLocale::Language::Bafia },
{ "Bafut\0", "bfd\0", QLocale::Language::Bafut },
@ -349,7 +348,6 @@ static const struct languageTblData {
{ "Kurukh\0", "kru\0", QLocale::Language::Kurukh },
{ "Kutenai\0", "kut\0", QLocale::Language::Kutenai },
{ "Kwasio\0", "nmg\0", QLocale::Language::Kwasio },
{ "Kyrgyz\0", "ky\0", QLocale::Language::Kyrgyz },
{ "Ladino\0", "lad\0", QLocale::Language::Ladino },
{ "Lahnda\0", "lah\0", QLocale::Language::Lahnda },
{ "Lakota\0", "lkt\0", QLocale::Language::Lakota },
@ -402,7 +400,6 @@ static const struct languageTblData {
{ "Maltese\0", "mt\0", QLocale::Language::Maltese },
{ "Manchu\0", "mnc\0", QLocale::Language::Manchu },
{ "Mandar\0", "mdr\0", QLocale::Language::Mandar },
{ "Mandarin Chinese\0", "zh\0", QLocale::Language::MandarinChinese },
{ "Mandingo\0", "man\0", QLocale::Language::Mandingo },
{ "Manipuri\0", "mni\0", QLocale::Language::Manipuri },
{ "Manx\0", "gv\0", QLocale::Language::Manx },
@ -444,7 +441,6 @@ static const struct languageTblData {
{ "Multiple languages\0", "mul\0", QLocale::Language::Multiplelanguages },
{ "Mundang\0", "mua\0", QLocale::Language::Mundang },
{ "Muslim Tat\0", "ttt\0", QLocale::Language::MuslimTat },
{ "Myanmar Language\0", "my\0", QLocale::Language::MyanmarLanguage },
{ "Myene\0", "mye\0", QLocale::Language::Myene },
{ "NKo\0", "nqo\0", QLocale::Language::NKo },
{ "Najdi Arabic\0", "ars\0", QLocale::Language::NajdiArabic },
@ -514,7 +510,6 @@ static const struct languageTblData {
{ "Portuguese\0", "pt\0", QLocale::Language::Portuguese },
{ "Prussian\0", "prg\0", QLocale::Language::Prussian },
{ "Punjabi\0", "pa\0", QLocale::Language::Punjabi },
{ "Pushto\0", "ps\0", QLocale::Language::Pushto },
{ "Quechua\0", "qu\0", QLocale::Language::Quechua },
{ "Rajasthani\0", "raj\0", QLocale::Language::Rajasthani },
{ "Rapanui\0", "rap\0", QLocale::Language::Rapanui },
@ -639,8 +634,6 @@ static const struct languageTblData {
{ "Tuvinian\0", "tyv\0", QLocale::Language::Tuvinian },
{ "Twi\0", "tw\0", QLocale::Language::Twi },
{ "Tyap\0", "kcg\0", QLocale::Language::Tyap },
{ "UK English\0", "en_GB\0", QLocale::Language::UKEnglish },
{ "US English\0", "en_US\0", QLocale::Language::USEnglish },
{ "Udmurt\0", "udm\0", QLocale::Language::Udmurt },
{ "Ugaritic\0", "uga\0", QLocale::Language::Ugaritic },
{ "Uighur\0", "ug\0", QLocale::Language::Uighur },
@ -649,7 +642,6 @@ static const struct languageTblData {
{ "Unknown language\0", "und\0", QLocale::Language::Unknownlanguage },
{ "Upper Sorbian\0", "hsb\0", QLocale::Language::UpperSorbian },
{ "Urdu\0", "ur\0", QLocale::Language::Urdu },
{ "Uyghur\0", "ug\0", QLocale::Language::Uyghur },
{ "Uzbek\0", "uz\0", QLocale::Language::Uzbek },
{ "Vai\0", "vai\0", QLocale::Language::Vai },
{ "Venda\0", "ve\0", QLocale::Language::Venda },
@ -733,7 +725,6 @@ static const struct countryTblData {
{ "Bhutan\0", "BT\0", QLocale::Country::Bhutan },
{ "Bolivia\0", "BO\0", QLocale::Country::Bolivia },
{ "Bosnia\0", "BA\0", QLocale::Country::Bosnia },
{ "Bosnia & Herzegovina\0", "BA\0", QLocale::Country::BosniaAndHerzegovina },
{ "Botswana\0", "BW\0", QLocale::Country::Botswana },
{ "Bouvet Island\0", "BV\0", QLocale::Country::BouvetIsland },
{ "Brazil\0", "BR\0", QLocale::Country::Brazil },
@ -765,8 +756,6 @@ static const struct countryTblData {
{ "Comoros\0", "KM\0", QLocale::Country::Comoros },
{ "Congo - Brazzaville\0", "CG\0", QLocale::Country::CongoBrazzaville },
{ "Congo (DRC)\0", "CD\0", QLocale::Country::CongoDRC },
{ "Congo - Kinshasa\0", "CD\0", QLocale::Country::CongoKinshasa },
{ "Congo (Republic)\0", "CG\0", QLocale::Country::CongoRepublic },
{ "Cook Islands\0", "CK\0", QLocale::Country::CookIslands },
{ "Costa Rica\0", "CR\0", QLocale::Country::CostaRica },
{ "Côte dIvoire\0", "CI\0", QLocale::Country::CotedIvoire },
@ -775,7 +764,6 @@ static const struct countryTblData {
{ "Curaçao\0", "CW\0", QLocale::Country::Curacao },
{ "Cyprus\0", "CY\0", QLocale::Country::Cyprus },
{ "Czech Republic\0", "CZ\0", QLocale::Country::CzechRepublic },
{ "Czechia\0", "CZ\0", QLocale::Country::Czechia },
{ "Denmark\0", "DK\0", QLocale::Country::Denmark },
{ "Diego Garcia\0", "DG\0", QLocale::Country::DiegoGarcia },
{ "Djibouti\0", "DJ\0", QLocale::Country::Djibouti },
@ -797,7 +785,6 @@ static const struct countryTblData {
{ "European Union\0", "EU\0", QLocale::Country::EuropeanUnion },
{ "Eurozone\0", "EZ\0", QLocale::Country::Eurozone },
{ "Falkland Islands\0", "FK\0", QLocale::Country::FalklandIslands },
{ "Falkland Islands (Islas Malvinas)\0", "FK\0", QLocale::Country::FalklandIslandsIslasMalvinas },
{ "Faroe Islands\0", "FO\0", QLocale::Country::FaroeIslands },
{ "Fiji\0", "FJ\0", QLocale::Country::Fiji },
{ "Finland\0", "FI\0", QLocale::Country::Finland },
@ -825,7 +812,6 @@ static const struct countryTblData {
{ "Heard & McDonald Islands\0", "HM\0", QLocale::Country::HeardAndMcDonaldIslands },
{ "Honduras\0", "HN\0", QLocale::Country::Honduras },
{ "Hong Kong\0", "HK\0", QLocale::Country::HongKong },
{ "Hong Kong SAR China\0", "HK\0", QLocale::Country::HongKongSARChina },
{ "Hungary\0", "HU\0", QLocale::Country::Hungary },
{ "Iceland\0", "IS\0", QLocale::Country::Iceland },
{ "India\0", "IN\0", QLocale::Country::India },
@ -836,7 +822,6 @@ static const struct countryTblData {
{ "Isle of Man\0", "IM\0", QLocale::Country::IsleofMan },
{ "Israel\0", "IL\0", QLocale::Country::Israel },
{ "Italy\0", "IT\0", QLocale::Country::Italy },
{ "Ivory Coast\0", "CI\0", QLocale::Country::IvoryCoast },
{ "Jamaica\0", "JM\0", QLocale::Country::Jamaica },
{ "Japan\0", "JP\0", QLocale::Country::Japan },
{ "Jersey\0", "JE\0", QLocale::Country::Jersey },
@ -858,7 +843,6 @@ static const struct countryTblData {
{ "Lithuania\0", "LT\0", QLocale::Country::Lithuania },
{ "Luxembourg\0", "LU\0", QLocale::Country::Luxembourg },
{ "Macao\0", "MO\0", QLocale::Country::Macao },
{ "Macao SAR China\0", "MO\0", QLocale::Country::MacaoSARChina },
{ "Madagascar\0", "MG\0", QLocale::Country::Madagascar },
{ "Malawi\0", "MW\0", QLocale::Country::Malawi },
{ "Malaysia\0", "MY\0", QLocale::Country::Malaysia },
@ -883,7 +867,6 @@ static const struct countryTblData {
{ "Morocco\0", "MA\0", QLocale::Country::Morocco },
{ "Mozambique\0", "MZ\0", QLocale::Country::Mozambique },
{ "Myanmar\0", "MM\0", QLocale::Country::Myanmar },
{ "Myanmar (Burma)\0", "MM\0", QLocale::Country::MyanmarBurma },
{ "Namibia\0", "NA\0", QLocale::Country::Namibia },
{ "Nauru\0", "NR\0", QLocale::Country::Nauru },
{ "Nepal\0", "NP\0", QLocale::Country::Nepal },
@ -909,7 +892,6 @@ static const struct countryTblData {
{ "Pakistan\0", "PK\0", QLocale::Country::Pakistan },
{ "Palau\0", "PW\0", QLocale::Country::Palau },
{ "Palestine\0", "PS\0", QLocale::Country::Palestine },
{ "Palestinian Territories\0", "PS\0", QLocale::Country::PalestinianTerritories },
{ "Panama\0", "PA\0", QLocale::Country::Panama },
{ "Papua New Guinea\0", "PG\0", QLocale::Country::PapuaNewGuinea },
{ "Paraguay\0", "PY\0", QLocale::Country::Paraguay },
@ -963,7 +945,6 @@ static const struct countryTblData {
{ "Sudan\0", "SD\0", QLocale::Country::Sudan },
{ "Suriname\0", "SR\0", QLocale::Country::Suriname },
{ "Svalbard & Jan Mayen\0", "SJ\0", QLocale::Country::SvalbardAndJanMayen },
{ "Swaziland\0", "SZ\0", QLocale::Country::Swaziland },
{ "Sweden\0", "SE\0", QLocale::Country::Sweden },
{ "Switzerland\0", "CH\0", QLocale::Country::Switzerland },
{ "Syria\0", "SY\0", QLocale::Country::Syria },
@ -971,7 +952,6 @@ static const struct countryTblData {
{ "Tajikistan\0", "TJ\0", QLocale::Country::Tajikistan },
{ "Tanzania\0", "TZ\0", QLocale::Country::Tanzania },
{ "Thailand\0", "TH\0", QLocale::Country::Thailand },
{ "Timor-Leste\0", "TL\0", QLocale::Country::TimorLeste },
{ "Togo\0", "TG\0", QLocale::Country::Togo },
{ "Tokelau\0", "TK\0", QLocale::Country::Tokelau },
{ "Tonga\0", "TO\0", QLocale::Country::Tonga },
@ -988,9 +968,6 @@ static const struct countryTblData {
{ "Uganda\0", "UG\0", QLocale::Country::Uganda },
{ "Ukraine\0", "UA\0", QLocale::Country::Ukraine },
{ "United Arab Emirates\0", "AE\0", QLocale::Country::UnitedArabEmirates },
{ "United Kingdom\0", "GB\0", QLocale::Country::UnitedKingdom },
{ "United Nations\0", "UN\0", QLocale::Country::UnitedNations },
{ "United States\0", "US\0", QLocale::Country::UnitedStates },
{ "U.S. Outlying Islands\0", "UM\0", QLocale::Country::UnitedStatesOutlyingIslands },
{ "U.S. Virgin Islands\0", "VI\0", QLocale::Country::UnitedStatesVirginIslands },
{ "Unknown Region\0", "ZZ\0", QLocale::Country::UnknownRegion },
@ -1155,7 +1132,6 @@ static const struct scriptTblData {
{ "Pahawh Hmong\0", "Hmng\0", QLocale::Script::PahawhHmongScript },
{ "Palmyrene\0", "Palm\0", QLocale::Script::PalmyreneScript },
{ "Pau Cin Hau\0", "Pauc\0", QLocale::Script::PauCinHauScript },
{ "Perso-Arabic\0", "Arab\0", QLocale::Script::PersoArabicScript },
{ "Phags-pa\0", "Phag\0", QLocale::Script::PhagspaScript },
{ "Phoenician\0", "Phnx\0", QLocale::Script::PhoenicianScript },
{ "Pollard Phonetic\0", "Plrd\0", QLocale::Script::PollardPhoneticScript },
@ -1172,12 +1148,10 @@ static const struct scriptTblData {
{ "Siddham\0", "Sidd\0", QLocale::Script::SiddhamScript },
{ "SignWriting\0", "Sgnw\0", QLocale::Script::SignWritingScript },
{ "Simplified Han\0", "Hans\0", QLocale::Script::SimplifiedHanScript },
{ "Simplified\0", "Hans\0", QLocale::Script::SimplifiedScript },
{ "Sinhala\0", "Sinh\0", QLocale::Script::SinhalaScript },
{ "Sogdian\0", "Sogd\0", QLocale::Script::SogdianScript },
{ "Sora Sompeng\0", "Sora\0", QLocale::Script::SoraSompengScript },
{ "Soyombo\0", "Soyo\0", QLocale::Script::SoyomboScript },
{ "Sumero-Akkadian Cuneiform\0", "Xsux\0", QLocale::Script::SumeroAkkadianCuneiformScript },
{ "Sundanese\0", "Sund\0", QLocale::Script::SundaneseScript },
{ "Syloti Nagri\0", "Sylo\0", QLocale::Script::SylotiNagriScript },
{ "Symbols\0", "Zsym\0", QLocale::Script::SymbolsScript },
@ -1197,10 +1171,8 @@ static const struct scriptTblData {
{ "Tifinagh\0", "Tfng\0", QLocale::Script::TifinaghScript },
{ "Tirhuta\0", "Tirh\0", QLocale::Script::TirhutaScript },
{ "Traditional Han\0", "Hant\0", QLocale::Script::TraditionalHanScript },
{ "Traditional\0", "Hant\0", QLocale::Script::TraditionalScript },
{ "UCAS\0", "Cans\0", QLocale::Script::UCASScript },
{ "Ugaritic\0", "Ugar\0", QLocale::Script::UgariticScript },
{ "Unified Canadian Aboriginal Syllabics\0", "Cans\0", QLocale::Script::UnifiedCanadianAboriginalSyllabicsScript },
{ "Unwritten\0", "Zxxx\0", QLocale::Script::UnwrittenScript },
{ "Vai\0", "Vaii\0", QLocale::Script::VaiScript },
{ "Varang Kshiti\0", "Wara\0", QLocale::Script::VarangKshitiScript },