Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format_timedelta() for minutes=1 and hours=1 with narrow format and pt_BR locale returns an empty string #892

Closed
jun66j5 opened this issue Jul 7, 2022 · 2 comments · Fixed by #1075

Comments

@jun66j5
Copy link
Contributor

jun66j5 commented Jul 7, 2022

Overview Description

format_timedelta() for minutes=1 and hours=1 with narrow format and pt_BR locale returns an empty string.

Steps to Reproduce

>>> import babel
>>> babel.__version__
'2.10.3'
>>> from datetime import timedelta
>>> from babel import dates
>>> dates.format_timedelta(timedelta(seconds=1), format='narrow', locale='pt_BR')
'1 s'
>>> dates.format_timedelta(timedelta(minutes=1), format='narrow', locale='pt_BR')
''
>>> dates.format_timedelta(timedelta(hours=1), format='narrow', locale='pt_BR')
''
>>> dates.format_timedelta(timedelta(days=1), format='narrow', locale='pt_BR')
'1 dia'
>>> dates.format_timedelta(timedelta(days=30), format='narrow', locale='pt_BR')
'1 mês'
>>> dates.format_timedelta(timedelta(days=365), format='narrow', locale='pt_BR')
'1 ano'

Actual Results

See "Steps to Reproduce"

Expected Results

Probably, 1 hora and 1 min.

Reproducibility

Always.

Additional Information

In common/main/pt.xml file:

  • duration-hour has only displayName element
  • duration-minute is missing
                <unitLength type="narrow">
                        ...
                        <unit type="duration-day">
                                <displayName>dia</displayName>
                                <unitPattern count="one">{0} dia</unitPattern>
                                <unitPattern count="other">{0} dias</unitPattern>
                                <perUnitPattern>{0}/dia</perUnitPattern>
                        </unit>
                        <unit type="duration-hour">
                                <displayName>hora</displayName>
                        </unit>
                        <unit type="duration-second">
                                <displayName>seg</displayName>
                                <unitPattern count="one">{0} s</unitPattern>
                                <unitPattern count="other">{0} s</unitPattern>
                                <perUnitPattern>{0}/seg</perUnitPattern>
                        </unit>
@PoncinMatthieu
Copy link

Seeing the same issue with locale pl

@jun66j5
Copy link
Contributor Author

jun66j5 commented Feb 23, 2023

I suspect the root cause is that common/main/root.xml file has the following rule for the narrow format, however parse_unit_patterns in scripts/import_cldr.py doesn't process the alias element.

		<unitLength type="narrow">
			<alias source="locale" path="../unitLength[@type='short']"/>
		</unitLength>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants