summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2003-03-12 22:53:25 +0000
committerbwarsaw2003-03-12 22:53:25 +0000
commit178465503af7269b6e60f8ef2a402ab9252ec95b (patch)
treee90f5472b1e9857b5992a18f55edfe9e4ec357ce
parent4b28e242feaa00d61d22e7df045d836897ede59c (diff)
downloadmailman-178465503af7269b6e60f8ef2a402ab9252ec95b.tar.gz
mailman-178465503af7269b6e60f8ef2a402ab9252ec95b.tar.zst
mailman-178465503af7269b6e60f8ef2a402ab9252ec95b.zip
_(): Encode any Unicode values in the interpolation dictionary back
into encoded 8-bit strings. Returning Unicode from here caused too much breakage, so we go in the other direction. Eventually, Mailman should use Unicode for everything (maybe). This should fix (one of) Peer's problems, and maybe the one recently reported by Dan Buchmann.
-rw-r--r--Mailman/i18n.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/Mailman/i18n.py b/Mailman/i18n.py
index d38eba85b..c58534384 100644
--- a/Mailman/i18n.py
+++ b/Mailman/i18n.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2000,2001,2002 by the Free Software Foundation, Inc.
+# Copyright (C) 2000-2003 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,7 +17,7 @@
import sys
import time
import gettext
-from types import StringType
+from types import StringType, UnicodeType
from Mailman import mm_cfg
from Mailman.SafeDict import SafeDict
@@ -74,8 +74,19 @@ def _(s):
# missing key in the dictionary.
dict = SafeDict(frame.f_globals.copy())
dict.update(frame.f_locals)
- # Translate the string, then interpolate into it.
- return _translation.gettext(s) % dict
+ # Translating the string returns an encoded 8-bit string. Rather than
+ # turn that into a Unicode, we turn any Unicodes in the dictionary values
+ # into encoded 8-bit strings. BAW: Returning a Unicode here broke too
+ # much other stuff and _() has many tentacles. Eventually I think we want
+ # to use Unicode everywhere.
+ tns = _translation.gettext(s)
+ charset = _translation.charset()
+ if not charset:
+ charset = 'us-ascii'
+ for k, v in dict.items():
+ if isinstance(v, UnicodeType):
+ dict[k] = v.encode(charset, 'replace')
+ return tns % dict