aboutsummaryrefslogtreecommitdiffstats
path: root/Mailman/i18n.py
diff options
context:
space:
mode:
authorMark Sapiro <mark@msapiro.net>2016-02-27 15:21:12 -0800
committerMark Sapiro <mark@msapiro.net>2016-02-27 15:21:12 -0800
commit95385417e926517c13ee769ef915ce5710a515f2 (patch)
treea39eccce0b844476a3715f328ee6712a5d62640e /Mailman/i18n.py
parent1833e1e51f4994d733c4ef3fca7c6ef7a4fd519e (diff)
parentb3e0912e4d982e53eccac906fad347e8f1792b97 (diff)
downloadmailman2-95385417e926517c13ee769ef915ce5710a515f2.tar.gz
mailman2-95385417e926517c13ee769ef915ce5710a515f2.tar.xz
mailman2-95385417e926517c13ee769ef915ce5710a515f2.zip
Fixed l10n to use correct charset for command-line scripts.
Diffstat (limited to 'Mailman/i18n.py')
-rw-r--r--Mailman/i18n.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/Mailman/i18n.py b/Mailman/i18n.py
index 5f926b77..102bee83 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,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())
@@ -95,6 +105,19 @@ def _(s):
+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
# of the strings anyway.