Back to index

plone3  3.1.7
lazycatalog.py
Go to the documentation of this file.
00001 from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
00002 from zope.i18n.gettextmessagecatalog import _KeyErrorRaisingFallback
00003 
00004 
00005 class LazyGettextMessageCatalog(GettextMessageCatalog):
00006     """A gettext message catalog which doesn't parse the files until they
00007        are accessed first.
00008     """
00009 
00010     def __init__(self, language, domain, path_to_file):
00011         """Initialize the message catalog"""
00012         self.language = language
00013         self.domain = domain
00014         self._path_to_file = path_to_file
00015         self._catalog = None
00016 
00017     def _check_reload(self):
00018         if self._catalog is None:
00019             self.reload()
00020             self._catalog.add_fallback(_KeyErrorRaisingFallback())
00021 
00022     def getMessage(self, id):
00023         'See IMessageCatalog'
00024         self._check_reload()
00025         return self._catalog.ugettext(id)
00026 
00027     def queryMessage(self, id, default=None):
00028         'See IMessageCatalog'
00029         self._check_reload()
00030         try:
00031             return self._catalog.ugettext(id)
00032         except KeyError:
00033             return default