Skip to content

Ukrainian locale should be uk not ua #955

@nykula

Description

@nykula
  • I am on the latest Pendulum version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • OS version and name: Alpine Linux 3.24.0_alpha20260127

  • Pendulum version: 3.2.0

Issue

Hello! PR #793 added Ukrainian localization with the code ua, but the ISO 639 language code, not to be confused with the ISO 3166 country code, is uk for the Ukrainian language, e.g. in GNU/Linux the locale is uk_UA.UTF-8, and browsers send headers like Accept-Language: uk-UA,uk to servers. What would be the correct way to make Pendulum use the correct uk language code, with a fallback to ua for backward compatibility?

>>> import locale
>>> import pendulum
>>> locale.getlocale()
('uk_UA', 'UTF-8')
>>> locale.getlocale()[0].split('_')[0]
'uk'
>>> pendulum.now('Europe/Kyiv').diff_for_humans(locale='uk')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/pendulum/src/pendulum/datetime.py", line 746, in diff_for_humans
    return pendulum.format_diff(diff, is_now, absolute, locale)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/pendulum/src/pendulum/helpers.py", line 171, in format_diff
    return _difference_formatter().format(diff, is_now, absolute, locale)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/pendulum/src/pendulum/formatting/difference_formatter.py", line 52, in format
    locale = self._locale if locale is None else Locale.load(locale)
                                                 ^^^^^^^^^^^^^^^^^^^
  File "/home/user/pendulum/src/pendulum/locales/locale.py", line 40, in load
    raise ValueError(f"Locale [{locale}] does not exist.")
ValueError: Locale [uk] does not exist.
>>> pendulum.now('Europe/Kyiv').diff_for_humans(locale='ua')
'кілька секунд тому'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions