Ejemplo n.º 1
0
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
    """
    target_folder = ITranslationLocator(content)(language)
    parent = aq_parent(content)
    cb_copy_data = parent.manage_cutObjects(content.getId())
    list_ids = target_folder.manage_pasteObjects(cb_copy_data)
    new_id = list_ids[0]['new_id']
    new_object = target_folder[new_id]
    return new_object
Ejemplo n.º 2
0
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
    """
    target_folder = ITranslationLocator(content)(language)
    parent = aq_parent(content)
    cb_copy_data = parent.manage_cutObjects(content.getId())
    list_ids = target_folder.manage_pasteObjects(cb_copy_data)
    new_id = list_ids[0]['new_id']
    new_object = target_folder[new_id]
    return new_object
Ejemplo n.º 3
0
    def __call__(self):
        """ Explore the site's content and place it on the right RLF
        """
        context = aq_inner(self.context)
        pl = getToolByName(context, "portal_languages")
        pu = getToolByName(context, "portal_url")
        portal = pu.getPortalObject()
        supported_langs = pl.getSupportedLanguages()

        output = []
        for path, obj in findObjects(portal):
            try:
                lang_adptr = ILanguage(obj)
            except:
                info_str = "Found object %s with no language support." % (path)
                logger.info(info_str)
                output.append(info_str)
                continue

            obj_lang = lang_adptr.get_language()
            if obj_lang not in supported_langs:
                info_str = "Found object %s with unsupported language %s." % (
                    path, obj_lang)
                logger.info(info_str)
                output.append(info_str)
            else:
                target_folder = ITranslationLocator(obj)(obj_lang)
                parent = aq_parent(obj)
                if IPloneSiteRoot.providedBy(parent) \
                   and ITranslatable.providedBy(obj) \
                   and not INavigationRoot.providedBy(obj):
                    target_folder = getattr(portal, obj_lang, None)

                if target_folder != parent:
                    cb_copy_data = parent.manage_cutObjects(obj.getId())
                    list_ids = target_folder.manage_pasteObjects(cb_copy_data)
                    new_id = list_ids[0]['new_id']
                    new_object = target_folder[new_id]
                    info_str = "Moved object %s to lang folder %s" % (
                        parent.getPhysicalPath(), obj_lang)
                    logger.info(info_str)
                    output.append(new_object.id)

        return output
Ejemplo n.º 4
0
    def __call__(self):
        """ Explore the site's content and place it on the right RLF
        """
        context = aq_inner(self.context)
        pl = getToolByName(context, "portal_languages")
        pu = getToolByName(context, "portal_url")
        portal = pu.getPortalObject()
        supported_langs = pl.getSupportedLanguages()

        output = []
        for path, obj in findObjects(portal):
            try:
                lang_adptr = ILanguage(obj)
            except:
                info_str = "Found object %s with no language support." % (path)
                logger.info(info_str)
                output.append(info_str)
                continue

            obj_lang = lang_adptr.get_language()
            if obj_lang not in supported_langs:
                info_str = "Found object %s with unsupported language %s." % (
                                            path, obj_lang)
                logger.info(info_str)
                output.append(info_str)
            else:
                target_folder = ITranslationLocator(obj)(obj_lang)
                parent = aq_parent(obj)
                if IPloneSiteRoot.providedBy(parent) \
                   and ITranslatable.providedBy(obj) \
                   and not INavigationRoot.providedBy(obj):
                    target_folder = getattr(portal, obj_lang, None)

                if target_folder != parent:
                    cb_copy_data = parent.manage_cutObjects(obj.getId())
                    list_ids = target_folder.manage_pasteObjects(cb_copy_data)
                    new_id = list_ids[0]['new_id']
                    new_object = target_folder[new_id]
                    info_str = "Moved object %s to lang folder %s" % (
                                            parent.getPhysicalPath(), obj_lang)
                    logger.info(info_str)
                    output.append(new_object.id)

        return output
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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