diff options
Diffstat (limited to 'util/locale_database/cldr2qlocalexml.py')
-rwxr-xr-x | util/locale_database/cldr2qlocalexml.py | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/util/locale_database/cldr2qlocalexml.py b/util/locale_database/cldr2qlocalexml.py index 0232120421..d3aa88ec38 100755 --- a/util/locale_database/cldr2qlocalexml.py +++ b/util/locale_database/cldr2qlocalexml.py @@ -1,44 +1,23 @@ #!/usr/bin/env python3 -# coding=utf8 -############################################################################# -## -## Copyright (C) 2021 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:GPL-EXCEPT$ -## Commercial License Usage -## Licensees holding valid commercial Qt licenses may use this file in -## accordance with the commercial license agreement provided with the -## Software or, alternatively, in accordance with the terms contained in -## a written agreement between you and The Qt Company. For licensing terms -## and conditions see https://www.qt.io/terms-conditions. For further -## information use the contact form at https://www.qt.io/contact-us. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 3 as published by the Free Software -## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -## included in the packaging of this file. Please review the following -## information to ensure the GNU General Public License requirements will -## be met: https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2021 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 """Convert CLDR data to QLocaleXML -The CLDR data can be downloaded from CLDR_, which has a sub-directory -for each version; you need the ``core.zip`` file for your version of -choice (typically the latest). This script has had updates to cope up -to v38.1; for later versions, we may need adaptations. Unpack the -downloaded ``core.zip`` and check it has a common/main/ sub-directory: -pass the path of that root of the download to this script as its first -command-line argument. Pass the name of the file in which to write -output as the second argument; either omit it or use '-' to select the -standard output. This file is the input needed by -``./qlocalexml2cpp.py`` +The CLDR data can be downloaded as a zip-file from CLDR_, which has a +sub-directory for each version; you need the ``core.zip`` file for +your version of choice (typically the latest), which you should then +unpack. Alternatively, you can clone the git repo from github_, which +has a tag for each release and a maint/maint-$ver branch for each +major version. Either way, the CLDR top-level directory should have a +subdirectory called common/ which contains (among other things) +subdirectories main/ and supplemental/. + +This script has had updates to cope up to v44.1; for later versions, +we may need adaptations. Pass the path of the CLDR top-level directory +to this script as its first command-line argument. Pass the name of +the file in which to write output as the second argument; either omit +it or use '-' to select the standard output. This file is the input +needed by ``./qlocalexml2cpp.py`` When you update the CLDR data, be sure to also update src/corelib/text/qt_attribution.json's entry for unicode-cldr. Check @@ -53,21 +32,30 @@ time zone names; see cldr2qtimezone.py for details. All the scripts mentioned support --help to tell you how to use them. -.. _CLDR: ftp://unicode.org/Public/cldr/ +.. _CLDR: https://unicode.org/Public/cldr/ +.. _github: https://github.com/unicode-org/cldr """ from pathlib import Path -import sys import argparse from cldr import CldrReader from qlocalexml import QLocaleXmlWriter -def main(out, err): - all_calendars = ['gregorian', 'persian', 'islamic'] # 'hebrew' +def main(argv, out, err): + """Generate a QLocaleXML file from CLDR data. + + Takes sys.argv, sys.stdout, sys.stderr (or equivalents) as + arguments. In argv[1:], it expects the root of the CLDR data + directory as first parameter and the name of the file in which to + save QLocaleXML data as second parameter. It accepts a --calendars + option to select which calendars to support (all available by + default).""" + all_calendars = ['gregorian', 'persian', 'islamic'] parser = argparse.ArgumentParser( + prog=Path(argv[0]).name, description='Generate QLocaleXML from CLDR data.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('cldr_path', help='path to the root of the CLDR tree') @@ -77,7 +65,7 @@ def main(out, err): nargs='+', metavar='CALENDAR', choices=all_calendars, default=all_calendars) - args = parser.parse_args() + args = parser.parse_args(argv[1:]) root = Path(args.cldr_path) root_xml_path = 'common/main/root.xml' @@ -102,7 +90,7 @@ def main(out, err): writer = QLocaleXmlWriter(emit.write) writer.version(reader.root.cldrVersion) - writer.enumData() + writer.enumData(reader.root.englishNaming) writer.likelySubTags(reader.likelySubTags()) writer.locales(reader.readLocales(args.calendars), args.calendars) @@ -110,4 +98,5 @@ def main(out, err): return 0 if __name__ == '__main__': - sys.exit(main(sys.stdout, sys.stderr)) + import sys + sys.exit(main(sys.argv, sys.stdout, sys.stderr)) |