def test_locator(self): folder_ca = createContentInContainer(self.portal['ca'], 'Folder', title=u"Test folder") subfolder_ca = createContentInContainer( self.portal['ca']['test-folder'], 'Folder', title=u"Test folder") locator = ITranslationLocator(subfolder_ca) self.assertEqual(locator('es'), self.portal['es']) ITranslationManager(folder_ca).add_translation('es') folder_es = ITranslationManager(folder_ca).get_translation('es') child_locator = ITranslationLocator(subfolder_ca) self.assertEqual(child_locator('es'), folder_es)
def reply(self): target_language = self.request.form["target_language"] locator = ITranslationLocator(self.context) parent = locator(target_language) return {"@id": parent.absolute_url()}
def add_translation_delegated(self, language): """ Creation is delegated to factory/++add++ Lets return the url where we are going to create the translation """ if not language and language != '': raise KeyError('There is no target language') # event notify(ObjectWillBeTranslatedEvent(self.context, language)) # localize where we need to store the new object locator = ITranslationLocator(self.context) parent = locator(language) return parent
def __call__(self, language): content_type = self.context.portal_type # parent for translation locator = ITranslationLocator(self.context) parent = locator(language) # id for translation name_chooser = ITranslationIdChooser(self.context) content_id = name_chooser(parent, language) # creating the translation new_id = parent.invokeFactory(type_name=content_type, id=content_id, language=language) new_content = getattr(parent, new_id) # clone language-independent content cloner = ITranslationCloner(self.context) cloner(new_content) return new_content
def multilingualMoveObject(content, language): """Move content object and its contained objects to a new language folder Also set the language on all the content moved """ if is_language_independent(content): # Language independent content will be created into language roo target_folder = getattr(getSite(), language) else: target_folder = ITranslationLocator(content)(language) parent = aq_parent(content) copy_data = parent.manage_cutObjects(content.getId()) list_ids = target_folder.manage_pasteObjects(copy_data) new_id = list_ids[0]['new_id'] new_object = target_folder[new_id] new_object.reindexObject() return new_object