Merged revisions 85223 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85223 | eric.araujo | 2010-10-05 01:52:37 +0200 (mar., 05 oct. 2010) | 3 lines Fix interaction of custom translation classes and caching (#9042) ........
This commit is contained in:
parent
2fdbfc507e
commit
298be5161f
|
@ -419,7 +419,7 @@ def translation(domain, localedir=None, languages=None,
|
|||
# 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:
|
||||
|
|
|
@ -335,6 +335,37 @@ class WeirdMetadataTest(GettextBaseTest):
|
|||
'John Doe <jdoe@example.com>\nJane Foobar <jfoobar@example.com>')
|
||||
|
||||
|
||||
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__)
|
||||
|
||||
|
|
Loading…
Reference in New Issue