Back to index

plone3  3.1.7
patches.py
Go to the documentation of this file.
00001 import os
00002 
00003 # Patch the Zope3 negotiator to cache the negotiated languages
00004 from Products.PlacelessTranslationService.memoize import memoize_second
00005 from zope.i18n.negotiator import Negotiator
00006 Negotiator.getLanguage = memoize_second(Negotiator.getLanguage)
00007 
00008 
00009 # Patch Zope3 to use a lazy message catalog, but only if we haven't
00010 # restricted the available catalogs in the first place.
00011 from Products.PlacelessTranslationService.load import PTS_LANGUAGES
00012 if PTS_LANGUAGES is not None:
00013     from zope.i18n import gettextmessagecatalog
00014     from Products.PlacelessTranslationService.lazycatalog import \
00015         LazyGettextMessageCatalog
00016     gettextmessagecatalog.GettextMessageCatalog = LazyGettextMessageCatalog
00017 
00018 
00019 # Patch the Zope3 i18n zcml statement to compile po files to mo
00020 from zope.i18n import zcml
00021 from Products.PlacelessTranslationService.load import _compile_locales_dir
00022 
00023 def wrap_compile_translations(func):
00024     def compile_translations(*args, **kwargs):
00025         if 'directory' in kwargs:
00026             _compile_locales_dir(kwargs.get('directory'))
00027         func(*args, **kwargs)
00028     return compile_translations
00029 
00030 # Apply patch
00031 zcml.registerTranslations = wrap_compile_translations(zcml.registerTranslations)