Skip to content

locale.nl_langinfo(locale.ALT_DIGITS) does not work #124969

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

ALT_DIGITS is a glibc specific item. It is supported by Python (there is an explicit list of supported items), but the result is not correct.

From The GNU C Library Reference Manual:

ALT_DIGITS

The return value is a representation of up to 100 values used to represent the values 0 to 99. As for ERA this value is not intended to be used directly, but instead indirectly through the strftime function. When the modifier O is used in a format which would otherwise use numerals to represent hours, minutes, seconds, weekdays, months, or weeks, the appropriate value for the locale is used instead.

This value is only defined in few locales: az_IR, fa_IR, ja_JP, lzh_TW, my_MM, or_IN, shn_MM.

But Python returns only one digit.

>>> import locale
>>> locale.setlocale(locale.LC_TIME, 'ja_JP')
'ja_JP'
>>> locale.setlocale(locale.LC_CTYPE, 'ja_JP')
'ja_JP'
>>> locale.nl_langinfo(locale.ALT_DIGITS)
'〇'

This is because nl_langinfo(ALT_DIGITS) in C returns a string with embedded null characters.

How should we fix it?

  • return a single string with 99 embedded null characters
  • return a 100-tuple of strings

What should we return if the value is not defined (in most locales) -- empty string (current behavior), empty tuple or None?

cc @methane

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions