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

Gettext deprecation fixes (for Python 3.11 compatibility) #835

Merged
merged 2 commits into from Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 17 additions & 13 deletions babel/support.py
Expand Up @@ -319,6 +319,9 @@ def ldgettext(self, domain, message):
"""Like ``lgettext()``, but look the message up in the specified
domain.
"""
import warnings
warnings.warn('ldgettext() is deprecated, use dgettext() instead',
DeprecationWarning, 2)
return self._domains.get(domain, self).lgettext(message)

def udgettext(self, domain, message):
Expand All @@ -339,6 +342,9 @@ def ldngettext(self, domain, singular, plural, num):
"""Like ``lngettext()``, but look the message up in the specified
domain.
"""
import warnings
warnings.warn('ldngettext() is deprecated, use dngettext() instead',
DeprecationWarning, 2)
return self._domains.get(domain, self).lngettext(singular, plural, num)

def udngettext(self, domain, singular, plural, num):
Expand Down Expand Up @@ -378,16 +384,12 @@ def lpgettext(self, context, message):
preferred system encoding, if no other encoding was explicitly set with
``bind_textdomain_codeset()``.
"""
ctxt_msg_id = self.CONTEXT_ENCODING % (context, message)
missing = object()
tmsg = self._catalog.get(ctxt_msg_id, missing)
if tmsg is missing:
if self._fallback:
return self._fallback.lpgettext(context, message)
return message
if self._output_charset:
return tmsg.encode(self._output_charset)
return tmsg.encode(locale.getpreferredencoding())
import warnings
warnings.warn('lpgettext() is deprecated, use pgettext() instead',
DeprecationWarning, 2)
tmsg = self.pgettext(context, message)
encoding = getattr(self, "_output_charset", None) or locale.getpreferredencoding()
return tmsg.encode(encoding)

def npgettext(self, context, singular, plural, num):
"""Do a plural-forms lookup of a message id. `singular` is used as the
Expand Down Expand Up @@ -417,12 +419,14 @@ def lnpgettext(self, context, singular, plural, num):
preferred system encoding, if no other encoding was explicitly set with
``bind_textdomain_codeset()``.
"""
import warnings
warnings.warn('lnpgettext() is deprecated, use npgettext() instead',
DeprecationWarning, 2)
ctxt_msg_id = self.CONTEXT_ENCODING % (context, singular)
try:
tmsg = self._catalog[(ctxt_msg_id, self.plural(num))]
if self._output_charset:
return tmsg.encode(self._output_charset)
return tmsg.encode(locale.getpreferredencoding())
encoding = getattr(self, "_output_charset", None) or locale.getpreferredencoding()
return tmsg.encode(encoding)
except KeyError:
if self._fallback:
return self._fallback.lnpgettext(context, singular, plural, num)
Expand Down