Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions scripts/import_cldr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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')))
Expand Down Expand Up @@ -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':
Expand Down
2 changes: 2 additions & 0 deletions tests/test_locale_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down