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

Doesn't work with Python 3.11 due to removed gettext.bind_textdomain_codeset API #710

Closed
hedayat opened this issue Sep 12, 2022 · 6 comments

Comments

@hedayat
Copy link
Member

hedayat commented Sep 12, 2022

Traceback (most recent call last):
  File "/usr/bin/hamster", line 415, in <module>
    i18n.setup_i18n()
  File "/usr/lib/python3.11/site-packages/hamster/lib/i18n.py", line 24, in setup_i18n
    module.bind_textdomain_codeset('hamster','utf8')
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'gettext' has no attribute 'bind_textdomain_codeset'

The mentioned line is removed in Python 3.11 (or 3.10 in fact), and removing it from the code fixes the problem.

@didierm
Copy link

didierm commented Dec 3, 2022

Monkey patch (restores compatibility with Python 3.11 / Fedora 37) :

try:
	module.bind_textdomain_codeset('hamster','utf8')
except AttributeError:
	pass
try:
	module.bindtextdomaincodeset('hamster','utf8')
except AttributeError:
	pass

@matthijskooijman matthijskooijman changed the title Doesn't work with Python 3.11 due to removed API Doesn't work with Python 3.11 due to removed gettext.bind_textdomain_codeset API Jan 4, 2023
@xevilstar
Copy link

xevilstar commented Jan 9, 2023

monkeypatch applied but

xevilstar@ghost:~$ python3 --version
Python 3.11.1
xevilstar@ghost:~$ hamster version
Traceback (most recent call last):
  File "/usr/bin/hamster", line 417, in <module>
    usage = _(
            ^
NameError: name '_' is not defined

seems it misses to import gettext correctly ?

@rhertzog
Copy link
Contributor

I think there's no point in keeping any "bind_textdomain_codeset" call at all. AFAIK gettext will return Unicode strings. The codeset is only relevant if you retrieve bytes out of the translation and I don't see why we would use functions that do that.

I have uploaded a fixed package in Debian unstable which switched to Python 3.11. It would be nice to have this fixed in git too (and maybe have a new release!).

https://salsa.debian.org/projecthamster-team/hamster-time-tracker/-/commit/ba336b272a216ae031b92eec5e5f78b0ed39047d

@xevilstar
Copy link

xevilstar commented Jan 10, 2023 via email

@mwilck
Copy link
Contributor

mwilck commented Jan 10, 2023

I have uploaded a fixed package in Debian unstable which switched to Python 3.11

Can you just create a PR?

@rhertzog
Copy link
Contributor

Can you just create a PR?

There's one already at #707 though you probably want to remove the line instead of commenting it out and update the explanation.

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

No branches or pull requests

6 participants