From b79d30b67b06307028eb47f817bdceebbe4e6151 Mon Sep 17 00:00:00 2001 From: AryanRG Date: Wed, 2 Dec 2026 04:05:53 +0530 Subject: [PATCH] Use the language plural rule when importing locales with a different text parent --- scripts/import_cldr.py | 17 ++++++++++------- tests/test_locale_class.py | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/import_cldr.py b/scripts/import_cldr.py index c4dae2fc4..641773ac8 100755 --- a/scripts/import_cldr.py +++ b/scripts/import_cldr.py @@ -197,7 +197,7 @@ def process_data(srcdir, destdir, force=True, dump_json=False): global_path = os.path.join(destdir, 'global.dat') global_data = parse_global(srcdir, sup) write_datafile(global_path, global_data, dump_json=dump_json) - _process_local_datas(sup, srcdir, destdir, dump_json=dump_json, zone_aliases=global_data['zone_aliases']) + _process_local_datas(sup, srcdir, destdir, global_data, dump_json=dump_json) def parse_global(srcdir, sup): @@ -363,7 +363,7 @@ def parse_global(srcdir, sup): return global_data -def _process_local_datas(sup, srcdir, destdir, force=True, dump_json=False, zone_aliases=None): +def _process_local_datas(sup, srcdir, destdir, global_data, force=True, dump_json=False): if not force: warnings.warn("Setting `force=False` has no effect.", DeprecationWarning, stacklevel=2) day_period_rules = parse_day_period_rules(parse(os.path.join(srcdir, 'supplemental', 'dayPeriods.xml'))) @@ -427,17 +427,20 @@ def _process_local_datas(sup, srcdir, destdir, force=True, dump_json=False, zone data['locale_id'] = locale_id data['unsupported_number_systems'] = set() - if locale_id in plural_rules: - data['plural_form'] = plural_rules[locale_id] - if locale_id in ordinal_rules: - data['ordinal_form'] = ordinal_rules[locale_id] + for field, rules in (('plural_form', plural_rules), ('ordinal_form', ordinal_rules)): + if locale_id in rules: + data[field] = rules[locale_id] + elif stem in global_data['parent_exceptions']: + # CLDR 49 has no parent overrides for the plurals component. + # For example, pt_AO inherits its text from pt_PT but its plurals from pt. + data[field] = rules.get(language, rules['root']) if locale_id in day_period_rules: data["day_period_rules"] = day_period_rules[locale_id] is_global = ("_" not in locale_id) parse_locale_display_names(data, tree, is_global=is_global) parse_list_patterns(data, tree) - parse_dates(data, tree, sup, regions, territory, zone_aliases or {}) + parse_dates(data, tree, sup, regions, territory, global_data['zone_aliases']) for calendar in tree.findall('.//calendars/calendar'): if calendar.attrib['type'] != 'gregorian': diff --git a/tests/test_locale_class.py b/tests/test_locale_class.py index a4061332b..d3ff0cae3 100644 --- a/tests/test_locale_class.py +++ b/tests/test_locale_class.py @@ -229,6 +229,8 @@ def test_plural_form_property(): assert Locale('en').plural_form(0) == 'other' assert Locale('fr').plural_form(0) == 'one' assert Locale('ru').plural_form(100) == 'many' + assert Locale('pt', 'PT').plural_form(0) == 'other' + assert Locale('pt', 'AO').plural_form(0) == 'one' def test_locale_provides_access_to_cldr_locale_data():