From 6aaafb6c05840389f1dd9139da9694f3b43c57df Mon Sep 17 00:00:00 2001 From: Yasuhito FUTATSUKI at POEM Date: Mon, 22 Feb 2016 17:51:37 +0900 Subject: Importing locale patch for command line utils, from RHEL6 rpm source (for -japan-poem, originally imported from 2.1.12-18 package for RHEL6 rpm source) --- Mailman/i18n.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'Mailman/i18n.py') diff --git a/Mailman/i18n.py b/Mailman/i18n.py index 5f926b77..0cfdb995 100644 --- a/Mailman/i18n.py +++ b/Mailman/i18n.py @@ -15,6 +15,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. +import locale import sys import time import gettext @@ -25,6 +26,15 @@ from Mailman.SafeDict import SafeDict _translation = None + +def _get_ctype_charset(): + old = locale.setlocale(locale.LC_CTYPE, '') + charset = locale.nl_langinfo(locale.CODESET) + locale.setlocale(locale.LC_CTYPE, old) + return charset + +_ctype_charset = _get_ctype_charset() + def set_language(language=None): @@ -54,7 +64,7 @@ if _translation is None: -def _(s): +def _(s, frame = 1): if s == '': return s assert s @@ -70,7 +80,7 @@ def _(s): # original string is 1) locals dictionary, 2) globals dictionary. # # First, get the frame of the caller - frame = sys._getframe(1) + frame = sys._getframe(frame) # A `safe' dictionary is used so we won't get an exception if there's a # missing key in the dictionary. dict = SafeDict(frame.f_globals.copy()) @@ -94,6 +104,19 @@ def _(s): return tns + +def tolocale(s): + global _ctype_charset + if isinstance(s, UnicodeType): + return s + source = _translation.charset () + if not source: + return s + return unicode(s, source, 'replace').encode(_ctype_charset, 'replace') + +def C_(s): + return tolocale(_(s, 2)) + def ctime(date): # Don't make these module globals since we have to do runtime translation -- cgit v1.2.3 From 056b6a968fb3f96ba3bf4dcc00b82370c043154e Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Sat, 27 Feb 2016 20:38:34 -0800 Subject: Added switch to disable the l10n cset recoding. --- Mailman/i18n.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Mailman/i18n.py') diff --git a/Mailman/i18n.py b/Mailman/i18n.py index 102bee83..b8b527e0 100644 --- a/Mailman/i18n.py +++ b/Mailman/i18n.py @@ -33,7 +33,8 @@ def _get_ctype_charset(): locale.setlocale(locale.LC_CTYPE, old) return charset -_ctype_charset = _get_ctype_charset() +if not mm_cfg.DISABLE_COMMAND_LOCALE_CSET: + _ctype_charset = _get_ctype_charset() @@ -114,8 +115,12 @@ def tolocale(s): return s return unicode(s, source, 'replace').encode(_ctype_charset, 'replace') -def C_(s): - return tolocale(_(s, 2)) +if mm_cfg.DISABLE_COMMAND_LOCALE_CSET: + C_ = _ +else: + def C_(s): + return tolocale(_(s, 2)) + def ctime(date): -- cgit v1.2.3