Index: Lib/gettext.py =================================================================== --- Lib/gettext.py (revision 82145) +++ Lib/gettext.py (working copy) @@ -419,7 +419,7 @@ # once. result = None for mofile in mofiles: - key = os.path.abspath(mofile) + key = (class_, os.path.abspath(mofile)) t = _translations.get(key) if t is None: with open(mofile, 'rb') as fp: Index: Lib/test/test_gettext.py =================================================================== --- Lib/test/test_gettext.py (revision 82145) +++ Lib/test/test_gettext.py (working copy) @@ -335,6 +335,37 @@ 'John Doe \nJane Foobar ') +class DummyGNUTranslations(gettext.GNUTranslations): + def foo(self): + return 'foo' + + +class GettextCacheTestCase(GettextBaseTest): + def test_cache(self): + self.localedir = os.curdir + self.mofile = MOFILE + + self.assertEqual(len(gettext._translations), 0) + + t = gettext.translation('gettext', self.localedir) + + self.assertEqual(len(gettext._translations), 1) + + t = gettext.translation('gettext', self.localedir, + class_=DummyGNUTranslations) + + self.assertEqual(len(gettext._translations), 2) + self.assertEqual(t.__class__, DummyGNUTranslations) + + # Calling it again doesn't add to the cache + + t = gettext.translation('gettext', self.localedir, + class_=DummyGNUTranslations) + + self.assertEqual(len(gettext._translations), 2) + self.assertEqual(t.__class__, DummyGNUTranslations) + + def test_main(): support.run_unittest(__name__)