Skip to content

bpo-40275: import locale lazily in gettext #19905

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

Merged
merged 2 commits into from
May 14, 2020
Merged
Changes from 1 commit
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 @@ -275,6 +275,7 @@ def gettext(self, message):
return message

def lgettext(self, message):
import locale
import warnings
warnings.warn('lgettext() is deprecated, use gettext() instead',
DeprecationWarning, 2)
Expand All @@ -296,6 +297,7 @@ def ngettext(self, msgid1, msgid2, n):
return msgid2

def lngettext(self, msgid1, msgid2, n):
import locale
import warnings
warnings.warn('lngettext() is deprecated, use ngettext() instead',
DeprecationWarning, 2)
Expand Down Expand Up @@ -459,6 +461,7 @@ def _parse(self, fp):
transidx += 8

def lgettext(self, message):
import locale
import warnings
warnings.warn('lgettext() is deprecated, use gettext() instead',
DeprecationWarning, 2)
Expand All @@ -473,6 +476,7 @@ def lgettext(self, message):
return tmsg.encode(locale.getpreferredencoding())

def lngettext(self, msgid1, msgid2, n):
import locale
import warnings
warnings.warn('lngettext() is deprecated, use ngettext() instead',
DeprecationWarning, 2)
Expand Down Expand Up @@ -665,6 +669,7 @@ def dgettext(domain, message):
return t.gettext(message)

def ldgettext(domain, message):
import locale
import warnings
warnings.warn('ldgettext() is deprecated, use dgettext() instead',
DeprecationWarning, 2)
Expand Down Expand Up @@ -692,6 +697,7 @@ def dngettext(domain, msgid1, msgid2, n):
return t.ngettext(msgid1, msgid2, n)

def ldngettext(domain, msgid1, msgid2, n):
import locale
import warnings
warnings.warn('ldngettext() is deprecated, use dngettext() instead',
DeprecationWarning, 2)
Expand Down