Locale data extraction: deal with an old TODO

Unify generation of the data on enum-related names (and their indices)
with that of the data for the corresponding codes. This produces the
same tables, just in a different order, putting each code table right
after the name table and its indexing.

It'll mean more conflicts on picking future updates back to 6.8 and
before, but those should usually involve regenerating data anyway,
even when they don't get (visible) conflicts, so this'll just
encourage doing that.

As the TODO comment noted, the reason for keeping the table separate
was just that, during a major rewrite of the scripts (most of five
years ago), I wanted to be sure data didn't change. We've stabilised
plenty since then, so it's time to do that clean-up.

Change-Id: I0c3ee9d41d85debdba8b8b2624f137fadb6d8a3f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Edward Welbourne 2024-10-09 14:10:25 +02:00
parent f9336a05bc
commit 60c3e80903
2 changed files with 503 additions and 516 deletions

File diff suppressed because it is too large Load Diff

View File

@ -800,19 +800,8 @@ class LocaleDataWriter (LocaleSourceEditor):
out(f'"{code}" // {value[0]}\n')
out(';\n\n')
def languageNames(self, languages):
def languageNaming(self, languages, code_data: LanguageCodeData):
self.__writeNameData(self.writer.write, languages, 'language')
def scriptNames(self, scripts):
self.__writeNameData(self.writer.write, scripts, 'script')
def territoryNames(self, territories):
self.__writeNameData(self.writer.write, territories, 'territory')
# TODO: unify these next three into the previous three; kept
# separate for now to verify we're not changing data.
def languageCodes(self, languages, code_data: LanguageCodeData):
out = self.writer.write
out(f'constexpr std::array<LanguageCodeEntry, {len(languages)}> languageCodeList {{\n')
@ -839,10 +828,12 @@ class LocaleDataWriter (LocaleSourceEditor):
out('};\n\n')
def scriptCodes(self, scripts):
def scriptNaming(self, scripts):
self.__writeNameData(self.writer.write, scripts, 'script')
self.__writeCodeList(self.writer.write, scripts, 'script', 4)
def territoryCodes(self, territories): # TODO: unify with territoryNames()
def territoryNaming(self, territories):
self.__writeNameData(self.writer.write, territories, 'territory')
self.__writeCodeList(self.writer.write, territories, 'territory', 3)
class CalendarDataWriter (LocaleSourceEditor):
@ -1022,13 +1013,9 @@ def main(argv, out, err):
writer.localeIndex(reader.languageIndices(tuple(k[0] for k in locale_map)))
writer.localeData(locale_map, locale_keys)
writer.writer.write('\n')
writer.languageNames(reader.languages)
writer.scriptNames(reader.scripts)
writer.territoryNames(reader.territories)
# TODO: merge the next three into the previous three
writer.languageCodes(reader.languages, code_data)
writer.scriptCodes(reader.scripts)
writer.territoryCodes(reader.territories)
writer.languageNaming(reader.languages, code_data)
writer.scriptNaming(reader.scripts)
writer.territoryNaming(reader.territories)
except Exception as e:
err.write(f'\nError updating locale data: {e}\n')
if args.verbose > 0: