Skip to content

Make Ukrainian locale name follow ISO 639, update it and add tests#957

Open
nykula wants to merge 1 commit intopython-pendulum:masterfrom
nykula:master
Open

Make Ukrainian locale name follow ISO 639, update it and add tests#957
nykula wants to merge 1 commit intopython-pendulum:masterfrom
nykula:master

Conversation

@nykula
Copy link
Copy Markdown

@nykula nykula commented Apr 3, 2026

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Fixes #955.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 8, 2026

Merging this PR will not alter performance

✅ 1 untouched benchmark


Comparing nykula:master (3258088) with master (0a88aec)

Open in CodSpeed


def diff_for_humans():
d = pendulum.now().subtract(seconds=1)
assert d.diff_for_humans(locale=locale) == "кілька секунд тому"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert d.diff_for_humans(locale=locale) == "1 секунду тому"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pendulum considers diffs less than 10 seconds, including 0 or 1, to be "a few seconds", so I'd leave this test as is, which matches the behavior of other locales.


d = pendulum.now().subtract(weeks=2)
assert d.diff_for_humans(locale=locale) == "2 тижні тому"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d = pendulum.now().subtract(weeks=5)
assert d.diff_for_humans(locale=locale) == "5 тижнів тому"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weeks=5 behaves in the same way as months=1, resulting in 1 місяць тому. Should I add that assertion?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do other locales do here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All locales behave the same in this regard. @afastronomer most likely meant that from the grammar point of view, 2 weeks and 5 weeks correspond to different forms in Ukrainian. But the latter form is currently unused in Pendulum; there's no feature, that I know of, to get a human representation of a duration in a specific unit such as weeks. One way to get to the form is:

pendulum.locale('uk').translation(f"units.week.{pendulum.locale('uk').plural(5)}").format(5)
# -> '5 тижнів'


d = pendulum.now().subtract(days=2)
assert d.diff_for_humans(locale=locale) == "2 дні тому"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d = pendulum.now().subtract(days=5)
assert d.diff_for_humans(locale=locale) == "5 днів тому"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to check, thanks, will commit when I have more time.

Comment on lines +56 to +60
lower = locale.lower()
if lower == 'ua':
# Backward compatibility. Ukrainian was 'ua' initially.
lower = 'uk'
return lower
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need that, since the initial locale had the wrong code. @ashb what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ukrainian locale should be uk not ua

4 participants