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

bpo-40275: import locale lazily in gettext #19905

Merged
merged 2 commits into from
May 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
# find this format documented anywhere.


import locale
import os
import re
import sys
Expand Down Expand Up @@ -210,6 +209,7 @@ def func(n):


def _expand_lang(loc):
import locale
loc = locale.normalize(loc)
COMPONENT_CODESET = 1 << 0
COMPONENT_TERRITORY = 1 << 1
Expand Down Expand Up @@ -278,6 +278,7 @@ def lgettext(self, message):
import warnings
warnings.warn('lgettext() is deprecated, use gettext() instead',
DeprecationWarning, 2)
import locale
if self._fallback:
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'.*\blgettext\b.*',
Expand All @@ -299,6 +300,7 @@ def lngettext(self, msgid1, msgid2, n):
import warnings
warnings.warn('lngettext() is deprecated, use ngettext() instead',
DeprecationWarning, 2)
import locale
if self._fallback:
with warnings.catch_warnings():
warnings.filterwarnings('ignore', r'.*\blngettext\b.*',
Expand Down Expand Up @@ -462,6 +464,7 @@ def lgettext(self, message):
import warnings
warnings.warn('lgettext() is deprecated, use gettext() instead',
DeprecationWarning, 2)
import locale
missing = object()
tmsg = self._catalog.get(message, missing)
if tmsg is missing:
Expand All @@ -476,6 +479,7 @@ def lngettext(self, msgid1, msgid2, n):
import warnings
warnings.warn('lngettext() is deprecated, use ngettext() instead',
DeprecationWarning, 2)
import locale
try:
tmsg = self._catalog[(msgid1, self.plural(n))]
except KeyError:
Expand Down Expand Up @@ -668,6 +672,7 @@ def ldgettext(domain, message):
import warnings
warnings.warn('ldgettext() is deprecated, use dgettext() instead',
DeprecationWarning, 2)
import locale
codeset = _localecodesets.get(domain)
try:
with warnings.catch_warnings():
Expand Down Expand Up @@ -695,6 +700,7 @@ def ldngettext(domain, msgid1, msgid2, n):
import warnings
warnings.warn('ldngettext() is deprecated, use dngettext() instead',
DeprecationWarning, 2)
import locale
codeset = _localecodesets.get(domain)
try:
with warnings.catch_warnings():
Expand Down