diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-09 10:49:53 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-26 05:36:16 +0000 |
commit | 1d48bf34db40280c6e1f5a40b22b18f51f102660 (patch) | |
tree | 08450cbaa8699988219da2ef5011c3661da133fc /util/locale_database/qlocalexml2cpp.py | |
parent | cf19105e018314d1fb05bc91959f233d3d6747ba (diff) |
Automate updating of list of locales for testlocales
This old test program has bitrotted due to not being autogenerated as
part of CLDR updates. Amend qlocalexml2cpp.py to regenerate it and do
such an update. It was still using Qt5's QLocale enum numeric values,
many of which have changed in Qt6. Actually fixing the code so that it
compiles and runs can wait for a later commit.
Inspired by a patch supplied by Kizito Birabwa.
Task-number: QTBUG-124200
Change-Id: I33811313976a4860aad6d7b5b88a40c5b111a4fe
Reviewed-by: Mate Barany <mate.barany@qt.io>
Diffstat (limited to 'util/locale_database/qlocalexml2cpp.py')
-rwxr-xr-x | util/locale_database/qlocalexml2cpp.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/util/locale_database/qlocalexml2cpp.py b/util/locale_database/qlocalexml2cpp.py index a884459ae3..dcf1f04628 100755 --- a/util/locale_database/qlocalexml2cpp.py +++ b/util/locale_database/qlocalexml2cpp.py @@ -458,6 +458,23 @@ class CalendarDataWriter (LocaleSourceEditor): self.writer.write('};\n') months_data.write(self.writer) + +class TestLocaleWriter (LocaleSourceEditor): + def localeList(self, locales): + self.writer.write('const LocaleListItem g_locale_list[] = {\n') + from enumdata import language_map, territory_map + # TODO: update testlocales/ to include script. + # For now, only mention each (lang, land) pair once: + pairs = set((lang, land) for lang, script, land in locales) + for lang, script, land in locales: + if (lang, land) in pairs: + pairs.discard((lang, land)) + langName = language_map[lang][0] + landName = territory_map[land][0] + self.writer.write(f' {{ {lang:6d},{land:6d} }}, // {langName}/{landName}\n') + self.writer.write('};\n\n') + + class LocaleHeaderWriter (SourceFileEditor): def __init__(self, path, temp, enumify): super().__init__(path, temp) @@ -594,6 +611,15 @@ def main(out, err): err.write(f'\nError updating qlocale.h: {e}\n') return 1 + # ./testlocales/localemodel.cpp + try: + path = 'util/locale_database/testlocales/localemodel.cpp' + with TestLocaleWriter(qtsrcdir.joinpath(path), qtsrcdir, + reader.cldrVersion) as test: + test.localeList(locale_keys) + except Exception as e: + err.write(f'\nError updating localemodel.cpp: {e}\n') + return 0 if __name__ == "__main__": |