Skip to content

Commit 7443d42

Browse files
authored
bpo-40275: Import locale module lazily in gettext (GH-19905)
1 parent 6f2f475 commit 7443d42

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Lib/gettext.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
# find this format documented anywhere.
4747

4848

49-
import locale
5049
import os
5150
import re
5251
import sys
@@ -210,6 +209,7 @@ def func(n):
210209

211210

212211
def _expand_lang(loc):
212+
import locale
213213
loc = locale.normalize(loc)
214214
COMPONENT_CODESET = 1 << 0
215215
COMPONENT_TERRITORY = 1 << 1
@@ -278,6 +278,7 @@ def lgettext(self, message):
278278
import warnings
279279
warnings.warn('lgettext() is deprecated, use gettext() instead',
280280
DeprecationWarning, 2)
281+
import locale
281282
if self._fallback:
282283
with warnings.catch_warnings():
283284
warnings.filterwarnings('ignore', r'.*\blgettext\b.*',
@@ -299,6 +300,7 @@ def lngettext(self, msgid1, msgid2, n):
299300
import warnings
300301
warnings.warn('lngettext() is deprecated, use ngettext() instead',
301302
DeprecationWarning, 2)
303+
import locale
302304
if self._fallback:
303305
with warnings.catch_warnings():
304306
warnings.filterwarnings('ignore', r'.*\blngettext\b.*',
@@ -462,6 +464,7 @@ def lgettext(self, message):
462464
import warnings
463465
warnings.warn('lgettext() is deprecated, use gettext() instead',
464466
DeprecationWarning, 2)
467+
import locale
465468
missing = object()
466469
tmsg = self._catalog.get(message, missing)
467470
if tmsg is missing:
@@ -476,6 +479,7 @@ def lngettext(self, msgid1, msgid2, n):
476479
import warnings
477480
warnings.warn('lngettext() is deprecated, use ngettext() instead',
478481
DeprecationWarning, 2)
482+
import locale
479483
try:
480484
tmsg = self._catalog[(msgid1, self.plural(n))]
481485
except KeyError:
@@ -668,6 +672,7 @@ def ldgettext(domain, message):
668672
import warnings
669673
warnings.warn('ldgettext() is deprecated, use dgettext() instead',
670674
DeprecationWarning, 2)
675+
import locale
671676
codeset = _localecodesets.get(domain)
672677
try:
673678
with warnings.catch_warnings():
@@ -695,6 +700,7 @@ def ldngettext(domain, msgid1, msgid2, n):
695700
import warnings
696701
warnings.warn('ldngettext() is deprecated, use dngettext() instead',
697702
DeprecationWarning, 2)
703+
import locale
698704
codeset = _localecodesets.get(domain)
699705
try:
700706
with warnings.catch_warnings():

0 commit comments

Comments
 (0)