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

Remove call to deprecated bind_textdomain_codeset gettext function #715

Merged
merged 1 commit into from
Mar 28, 2023

Conversation

fgrosse
Copy link
Contributor

@fgrosse fgrosse commented Mar 21, 2023

This function was deprecated and eventually removed in Python3.11 (see changelog at https://docs.python.org/3/whatsnew/3.11.html)

Removed the deprecated gettext functions lgettext(), ldgettext(),
lngettext() and ldngettext(). Also removed the bind_textdomain_codeset()
function, the NullTranslations.output_charset() and
NullTranslations.set_output_charset() methods, and the codeset parameter
of translation() and install(), since they are only used for the
l*gettext() functions. (Contributed by Dong-hee Na and Serhiy Storchaka
in bpo-44235.)

Fixes #714

This function was deprecated and eventually removed in Python3.11
(see changelog at https://docs.python.org/3/whatsnew/3.11.html)

> Removed the deprecated gettext functions lgettext(), ldgettext(),
> lngettext() and ldngettext(). Also removed the bind_textdomain_codeset()
> function, the NullTranslations.output_charset() and
> NullTranslations.set_output_charset() methods, and the codeset parameter
> of translation() and install(), since they are only used for the
> l*gettext() functions. (Contributed by Dong-hee Na and Serhiy Storchaka
> in bpo-44235.)
@fgrosse
Copy link
Contributor Author

fgrosse commented Mar 25, 2023

Looks like the build is already broken on the main branch or due to a reason external to this changeset.

It currently fails with:

Run actions/setup-python@v1
Error: Version 3.6 with arch x64 not found
Available versions:

3.10.10 (x64)
3.11.2 (x64)
3.7.16 (x64)
3.8.16 (x64)
3.9.16 (x64)

I don't think I can do anything about it myself.

@aquaherd
Copy link
Member

I also have a different approach in #693 'Failsafe localization' keeping the API for older runtimes but catching failsafe if it is no longer supported.

Copy link
Member

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

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

I've looked at this issue, and I think this is the proper fix. According to the 3.10 docs:

gettext.bind_textdomain_codeset(domain, codeset=None)

Bind the domain to codeset, changing the encoding of byte strings returned by the lgettext(), ldgettext(), lngettext() and ldngettext() functions. If codeset is omitted, then the current binding is returned.

This bind_textdomain_codeset only affects the l*gettext() methods, which we do not use at all.

On the same page, about the l*gettext() functions, I see:

These functions should be avoided in Python 3, because they return encoded bytes. It’s much better to use alternatives which return Unicode strings instead, since most Python applications will want to manipulate human readable text as strings instead of bytes. Further, it’s possible that you may get unexpected Unicode-related exceptions if there are encoding problems with the translated strings.

I suspect that this means that these functions were useful on python2 where string objects contained encoded strings (i.e. you needed to know their encoding to interpret them). In python3, string objects are decoded, so no need to know the encoding (unlike bytes objects, which can contain encoded strings).

Looking at upstream gettext docs, it seems the bind_textdomain_codeset does affect the regular *gettext() functions (upstream does not have the l*gettext() versions at all), but I think that the python bindings handle this internally (i.e. they get the string from the .mo file encoded in whatever charset, but then decodes it before returning it [here], so the application does not have to care about encodings at all.

Summarizing: This call can just be removed and has been unnecessary since python 3.0.

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.

App startup fails
4 participants