diff options
author | Aarni Koskela <akx@iki.fi> | 2022-04-08 13:33:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-08 13:33:34 +0300 |
commit | d93879493815cd8a76a0b3512c6ce238025e45e6 (patch) | |
tree | cdeedd9dbbca22bf358638d9e9b46e7897e669d5 | |
parent | 5aa000ec2955407271e660630e8db376adbc6858 (diff) | |
parent | 248fa358dd17f89f72a2cbc5bc29175dcc15be58 (diff) | |
download | babel-d93879493815cd8a76a0b3512c6ce238025e45e6.tar.gz |
Merge pull request #835 from akx/gettext-deprecations
Gettext deprecation fixes (for Python 3.11 compatibility)
-rw-r--r-- | babel/support.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/babel/support.py b/babel/support.py index 0e9716b..a22bffc 100644 --- a/babel/support.py +++ b/babel/support.py @@ -319,6 +319,9 @@ class NullTranslations(gettext.NullTranslations, object): """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): @@ -339,6 +342,9 @@ class NullTranslations(gettext.NullTranslations, object): """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): @@ -378,16 +384,12 @@ class NullTranslations(gettext.NullTranslations, object): 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 @@ -417,12 +419,14 @@ class NullTranslations(gettext.NullTranslations, object): 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) |