diff options
author | Yasuhito FUTATSUKI at POEM <futatuki@poem.co.jp> | 2016-03-02 18:57:16 +0900 |
---|---|---|
committer | Yasuhito FUTATSUKI at POEM <futatuki@poem.co.jp> | 2016-03-02 18:57:16 +0900 |
commit | 3d3ed445c841f40e793e733956ab65287ca5cfe1 (patch) | |
tree | f54b733b0a6a3353cb595d6c4664689ea5bf8a3f /Mailman/i18n.py | |
parent | 7bee928877b9771072c32c47912b346b41ce3c35 (diff) | |
parent | 8f22ba21a32701d2efaac0b8b1a1c0a4522912b0 (diff) | |
download | mailman2-3d3ed445c841f40e793e733956ab65287ca5cfe1.tar.gz mailman2-3d3ed445c841f40e793e733956ab65287ca5cfe1.tar.xz mailman2-3d3ed445c841f40e793e733956ab65287ca5cfe1.zip |
Update to lp:mailman/2.1 rev 1629 (no difference against the original branch
Diffstat (limited to '')
-rw-r--r-- | Mailman/i18n.py | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/Mailman/i18n.py b/Mailman/i18n.py index 5f926b77..b8b527e0 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,16 @@ 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() + def set_language(language=None): @@ -54,7 +65,7 @@ if _translation is None: -def _(s): +def _(s, frame=1): if s == '': return s assert s @@ -70,7 +81,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 +106,23 @@ 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') + +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. |