diff options
author | Edward Welbourne <eddy@chaos.org.uk> | 2020-03-17 17:39:43 +0100 |
---|---|---|
committer | Edward Welbourne <eddy@chaos.org.uk> | 2020-04-02 19:44:06 +0100 |
commit | cabd8f860b54c1692bd03876c1bfcc3e14b56503 (patch) | |
tree | e1613d38c5ec99acdde538237435d7cbd4a0bff4 | |
parent | 67c0e2878977d9e930c1fab6d29baa878cb86411 (diff) |
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 <cristian.maureira-fredes@qt.io>
-rwxr-xr-x | util/locale_database/cldr2qlocalexml.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/util/locale_database/cldr2qlocalexml.py b/util/locale_database/cldr2qlocalexml.py index b28dcecc45..690e6347da 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)) |