From 99bf4f49b61b79f8af5a7a9e609b4ac1b3fe231d Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Fri, 18 May 2001 20:14:53 +0000 Subject: Better support for command line scripts which want to set the default language to the value of $LANGUAGE (or any of the other gettext module supported environment variables). Specifically, set_language(): Allow the `language' parameter to default to None, which tells gettext.translation() to use its own defaults. When the module global _translation is None, call set_language() with no arguments. --- Mailman/i18n.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'Mailman/i18n.py') diff --git a/Mailman/i18n.py b/Mailman/i18n.py index 2dcacadc9..c1bb82249 100644 --- a/Mailman/i18n.py +++ b/Mailman/i18n.py @@ -20,21 +20,22 @@ import gettext from Mailman import mm_cfg from Mailman.SafeDict import SafeDict +_translation = None - -_translation = gettext.NullTranslations() -def set_language(language): + +def set_language(language=None): global _translation + if language is not None: + language = [language] try: _translation = gettext.translation('mailman', mm_cfg.MESSAGES_DIR, - [language]) + language) except IOError: # The selected language was not installed in messages, so fall back to # untranslated English. _translation = gettext.NullTranslations() - def get_translation(): return _translation @@ -43,6 +44,12 @@ def set_translation(translation): _translation = translation +# Set up the global translation based on environment variables. Mostly used +# for command line scripts. +if _translation is None: + set_language() + + def _x(s, frame): # Do translation of the given string into the current language, and do -- cgit v1.2.3-70-g09d2