def initialize(context): # hook into the Control Panel global translation_service # allow for disabling PTS entirely by setting a environment variable. if bool(os.getenv('DISABLE_PTS')): log('Disabled by environment variable "DISABLE_PTS".', logging.WARNING) return cp = context._ProductContext__app.Control_Panel # argh if cp_id in cp.objectIds(): cp_ts = getattr(cp, cp_id) # use the ts in the acquisition context of the control panel # translation_service = translation_service.__of__(cp) translation_service = PTSWrapper(cp_ts) else: cp_ts = make_translation_service(cp) # don't touch - this is the last version that didn't have the # attribute (0.4) instance_version = getattr(cp_ts, '_instance_version', (0, 4, 0, 0)) if instance_version[3] > 99: log('development mode: translation service recreated', detail = '(found %s.%s.%s.%s)\n' % instance_version) cp._delObject(cp_id) cp_ts = make_translation_service(cp) if instance_version < PlacelessTranslationService._class_version: log('outdated translation service found, recreating', detail = '(found %s.%s.%s.%s)\n' % instance_version) cp._delObject(cp_id) purgeMoFileCache() cp_ts = make_translation_service(cp) # sweep products log('products: %r' % get_products(), logging.DEBUG) for prod in get_products(): # prod is a tuple in the form: # (priority, dir_name, index, base_dir) for each Product directory cp_ts._load_i18n_dir(os.path.join(prod[3], prod[1], 'i18n')) cp_ts._load_locales_dir(os.path.join(prod[3], prod[1], 'locales')) # sweep the i18n directory for local catalogs instance_i18n = os.path.join(INSTANCE_HOME, 'i18n') if os.path.isdir(instance_i18n): cp_ts._load_i18n_dir(instance_i18n) instance_locales = os.path.join(INSTANCE_HOME, 'locales') if os.path.isdir(instance_locales): cp_ts._load_locales_dir(instance_locales) # didn't found any catalogs if not cp_ts.objectIds(): log('no translations found!', logging.DEBUG) # set ZPT's translation service # NOTE: since this registry is a global var we can't register the # persistent service itself (zodb connection) therefore a # wrapper is created around it setGlobalTranslationService(PTSWrapper(cp_ts))
def test_allowed_content_types_translated(self): """Tests allowed content types from the action menu are translated""" translation_service = DummyTranslationService() setGlobalTranslationService(translation_service) # assumes that we can add Business Template in template tool response = self.publish('%s/portal_templates' % self.portal_id, self.auth) self.assertEquals(HTTP_OK, response.getStatus()) self.failUnless(('Business Template', {}) in translation_service._translated['ui']) self.failUnless( ('Add ${portal_type}', {'portal_type': 'Business Template'}) in translation_service._translated['ui'])
def initialize(context): # XXX This code has been written by Cornel Nitu, it may be a solution to # upgrade instances. ## root = context._ProductContext__app ## for item in root.PrincipiaFind(root, obj_metatypes=['LocalContent'], ## search_sub=1): ## item[1].manage_upgrade() # Register the Localizer context.registerClass(Localizer.Localizer, constructors = (Localizer.manage_addLocalizerForm, Localizer.manage_addLocalizer), icon = 'img/localizer.gif') # Register LocalContent context.registerClass( LocalContent.LocalContent, constructors = (LocalContent.manage_addLocalContentForm, LocalContent.manage_addLocalContent), icon='img/local_content.gif') # Register MessageCatalog context.registerClass( MessageCatalog.MessageCatalog, constructors = (MessageCatalog.manage_addMessageCatalogForm, MessageCatalog.manage_addMessageCatalog), icon='img/message_catalog.gif') # Register LocalFolder context.registerClass( LocalFolder.LocalFolder, constructors = (LocalFolder.manage_addLocalFolderForm, LocalFolder.manage_addLocalFolder), icon='img/local_folder.gif') # Register LocalPropertyManager as base class for ZClasses ZClasses.createZClassForBase(LocalPropertyManager, globals(), 'LocalPropertyManager', 'LocalPropertyManager') context.registerHelp() # Register the dtml-gettext tag String.commands['gettext'] = GettextTag # Register the global translation service for the i18n namespace (ZPT) if PTSWrapper is None and TranslationService is None: setGlobalTranslationService(GlobalTranslationService())
def test_jump_action_translated(self): """Tests jump actions are translated""" translation_service = DummyTranslationService() setGlobalTranslationService(translation_service) # adds a new jump action to Template Tool portal type self.getTypesTool().getTypeInfo('Template Tool').newContent( portal_type='Action Information', reference='dummy_jump_action', title='Dummy Jump Action', action_permission='View', action_type='object_jump') response = self.publish('%s/portal_templates' % self.portal_id, self.auth) self.assertEquals(HTTP_OK, response.getStatus()) self.failUnless(('Dummy Jump Action', {}) in translation_service._translated['ui'])
def initialize(context): """ """ setGlobalTranslationService(GlobalTranslationService())
def initialize(context): """ """ setGlobalTranslationService(GlobalTranslationService())
def checkI18nTranslateHooked(self): old_ts = setGlobalTranslationService(TestTranslationService()) self.assert_expected(self.folder.t, 'CheckI18nTranslateHooked.html') setGlobalTranslationService(old_ts)
def initialize(context): # Check Localizer is not installed with a name different than Localizer # (this is a common mistake). filename = os.path.split(os.path.split(__file__)[0])[1] if filename != 'Localizer': message = ( "The Localizer product must be installed within the 'Products'" " folder with the name 'Localizer' (not '%s').") % filename raise RuntimeError, message # XXX This code has been written by Cornel Nitu, it may be a solution to # upgrade instances. ## root = context._ProductContext__app ## for item in root.PrincipiaFind(root, obj_metatypes=['LocalContent'], ## search_sub=1): ## item[1].manage_upgrade() # Register the Localizer context.registerClass(Localizer.Localizer, constructors = (Localizer.manage_addLocalizerForm, Localizer.manage_addLocalizer), icon = 'img/localizer.gif') # Register LocalContent context.registerClass( LocalContent.LocalContent, constructors = (LocalContent.manage_addLocalContentForm, LocalContent.manage_addLocalContent), icon='img/local_content.gif') # Register MessageCatalog context.registerClass( MessageCatalog.MessageCatalog, constructors = (MessageCatalog.manage_addMessageCatalogForm, MessageCatalog.manage_addMessageCatalog), icon='img/message_catalog.gif') # Register LocalFolder context.registerClass( LocalFolder.LocalFolder, constructors = (LocalFolder.manage_addLocalFolderForm, LocalFolder.manage_addLocalFolder), icon='img/local_folder.gif') try: import ZClasses # Register LocalPropertyManager as base class for ZClasses ZClasses.createZClassForBase(LocalPropertyManager, globals(), 'LocalPropertyManager', 'LocalPropertyManager') except ImportError: # >= no more ZClasses in Zope2.12 pass context.registerHelp() # Register the dtml-gettext tag String.commands['gettext'] = GettextTag # Register the global translation service for the i18n namespace (ZPT) if (PTSWrapper is None and TranslationService is None and setGlobalTranslationService_present is True): setGlobalTranslationService(GlobalTranslationService())
def checkI18nTranslateHooked(self): old_ts = setGlobalTranslationService(TestTranslationService()) self.assert_expected(self.folder.t, 'CheckI18nTranslateHooked.html') setGlobalTranslationService(old_ts)