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

Fix preference dialog breaking issue #13

Merged
merged 1 commit into from May 9, 2023
Merged

Fix preference dialog breaking issue #13

merged 1 commit into from May 9, 2023

Conversation

ZhennanWu
Copy link

Origin: https://bugs.gentoo.org/905906

Problem

When trying to open the preference for Chinese-Pinyin in ibus-setup, an error is thrown:

Traceback (most recent call last):
  File "/usr/share/ibus-pinyin/setup/main.py", line 432, in <module>
    main()
  File "/usr/share/ibus-pinyin/setup/main.py", line 428, in main
    PreferencesDialog(name).run()
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/ibus-pinyin/setup/main.py", line 48, in __init__
    gettext.bind_textdomain_codeset("ibus-pinyin", "UTF-8")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'gettext' has no attribute 'bind_textdomain_codeset'

Cause

The relevant APIs were already removed in Python 3.10:
https://bugs.python.org/issue40936
https://docs.python.org/3.10/library/gettext.html#gettext.bind_textdomain_codeset

This is a UX issue but does prevent basic functionalities.

Using python >=3.10 will raise this problem.

Potential Fix

By removing this single line seems to fix the issue. The preference can now function properly

File "/usr/share/ibus-pinyin/setup/main.py", line 48, in __init__
    gettext.bind_textdomain_codeset("ibus-pinyin", "UTF-8")

No further usages of removed API were found.

Disclaimer

I haven't performed deeper testing to see if the removal of this line will cause problem elsewhere

@epico
Copy link
Member

epico commented May 8, 2023

Please consider the following code:

DOMAINNAME = 'ibus-pinyin'

# Python's gettext module doesn't provide all methods in
# new Python version
try:
    gettext.bindtextdomain(DOMAINNAME, localedir)
    gettext.bind_textdomain_codeset(DOMAINNAME, 'UTF-8')
except AttributeError:
    pass

@epico epico changed the title Fix preference dialog breaking by removing deprecated python APIs Fix preference dialog breaking issue May 9, 2023
@epico
Copy link
Member

epico commented May 9, 2023

Please squash the two commits into one commit, thanks!

@ZhennanWu
Copy link
Author

@epico The commits are now squashed

@epico epico merged commit e2e10c4 into ibus:main May 9, 2023
@epico
Copy link
Member

epico commented May 9, 2023

Thanks for the patch!

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