1
# Copyright (C) 2009 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18
"""Internationalization for the tests."""
20
from __future__ import absolute_import, unicode_literals
24
'install_testing_i18n',
28
from contextlib import closing
29
from flufl.i18n import registry
30
from gettext import GNUTranslations, NullTranslations
31
from pkg_resources import resource_stream
33
from mailman.core.i18n import initialize as core_initialize
37
class TestingStrategy:
38
"""A strategy that finds catalogs in the testing directory."""
40
def __init__(self, name):
43
def __call__(self, language_code):
44
if language_code == 'en':
45
return NullTranslations()
46
mo_file = 'mailman-%s.mo' % language_code
47
with closing(resource_stream('mailman.testing', mo_file)) as fp:
48
return GNUTranslations(fp)
53
"""Install a global underscore function for testing purposes."""
54
strategy = TestingStrategy('mailman-testing')
55
application = registry.register(strategy)
56
core_initialize(application)