aboutsummaryrefslogtreecommitdiffstats
path: root/Mailman/i18n.py
diff options
context:
space:
mode:
Diffstat (limited to 'Mailman/i18n.py')
-rw-r--r--Mailman/i18n.py36
1 files changed, 33 insertions, 3 deletions
diff --git a/Mailman/i18n.py b/Mailman/i18n.py
index 5f926b77..605d4e76 100644
--- a/Mailman/i18n.py
+++ b/Mailman/i18n.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2000-2010 by the Free Software Foundation, Inc.
+# Copyright (C) 2000-2016 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -17,6 +17,7 @@
import sys
import time
+import locale
import gettext
from types import StringType, UnicodeType
@@ -25,6 +26,18 @@ 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
+
+if not mm_cfg.DISABLE_COMMAND_LOCALE_CSET:
+ _ctype_charset = _get_ctype_charset()
+else:
+ _ctype_charset = None
+
def set_language(language=None):
@@ -54,7 +67,7 @@ if _translation is None:
-def _(s):
+def _(s, frame=1):
if s == '':
return s
assert s
@@ -70,7 +83,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())
@@ -95,6 +108,23 @@ def _(s):
+def tolocale(s):
+ global _ctype_charset
+ if isinstance(s, UnicodeType) or _ctype_charset is None:
+ return s
+ source = _translation.charset ()
+ if not source:
+ return s
+ return unicode(s, source, 'replace').encode(_ctype_charset, 'replace')
+
+if mm_cfg.DISABLE_COMMAND_LOCALE_CSET:
+ C_ = _
+else:
+ def C_(s):
+ return tolocale(_(s, 2))
+
+
+
def ctime(date):
# Don't make these module globals since we have to do runtime translation
# of the strings anyway.