From cabd8f860b54c1692bd03876c1bfcc3e14b56503 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 17 Mar 2020 17:39:43 +0100 Subject: [PATCH] Ensure we use UTF-8 for the emitted QLocaleXML data file Python helpfully uses a sensible locale when stdout is a tty but uses the system (not the filesystem) default encoding, which may be ascii and unable to encode some of the data we need to save. So brute force kludge it to ensure emit.encoding is UTF-8 when writing the output we'll read as UTF-8 anyway. (This matches dev's commit 0ef79d94f6dcf276ca55b084d27f980b1f260473 for the reworked version of the script.) Task-number: QTBUG-79902 Change-Id: I60ddc896a308c06e01fa87e8e18e112faa17d601 Reviewed-by: Cristian Maureira-Fredes --- util/locale_database/cldr2qlocalexml.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/locale_database/cldr2qlocalexml.py b/util/locale_database/cldr2qlocalexml.py index b28dcecc459..690e6347da2 100755 --- a/util/locale_database/cldr2qlocalexml.py +++ b/util/locale_database/cldr2qlocalexml.py @@ -55,6 +55,7 @@ time zone names; see cldr2qtimezone.py for details. """ import os +import sys from localetools import Error from cldr import CldrReader @@ -101,6 +102,10 @@ def main(args, out, err): usage(name, err, 'Too many arguments - excess: ' + ' '.join(args)) return 1 + if emit.encoding != 'UTF-8' or (emit.encoding is None and sys.getdefaultencoding() != 'UTF-8'): + reload(sys) # Weirdly, this gets a richer sys module than the plain import got us ! + sys.setdefaultencoding('UTF-8') + # TODO - command line options to tune choice of grumble and whitter: reader = CldrReader(root, err.write, err.write) writer = QLocaleXmlWriter(emit.write) @@ -114,5 +119,4 @@ def main(args, out, err): return 0 if __name__ == '__main__': - import sys sys.exit(main(sys.argv, sys.stdout, sys.stderr))