def get_parent_lrf(self):
        navigation_root = self.context
        while not (ILanguageRootFolder.providedBy(navigation_root)
                   or IPloneSiteRoot.providedBy(navigation_root)):
            navigation_root = aq_parent(navigation_root)

        if ILanguageRootFolder.providedBy(navigation_root):
            return navigation_root

        return None
def reindex_neutral(obj, event):
    # we need to look for the parent that is already indexed
    if IPloneSiteRoot.providedBy(obj) \
       or (not is_shared(obj) and not is_shared_original(obj)):
        return
    parent = aq_parent(obj)
    if ILanguageRootFolder.providedBy(parent):
        # If it's parent is language root folder no need to reindex
        return
    site = getSite()
    language_tool = getToolByName(site, 'portal_languages')
    language_infos = language_tool.supported_langs
    if IPloneSiteRoot.providedBy(parent):
        # It's plone site root we need to look at LRF
        for language_info in language_infos:
            lrf_to_reindex = getattr(parent, language_info, None)
            to_reindex = getattr(lrf_to_reindex, obj.id, None)
            if to_reindex is not None:
                to_reindex.reindexObject()
    else:
        content_id = IUUID(parent).split('-')[0]
        pc = getToolByName(site, 'portal_catalog')
        for language_info in language_infos:
            brains = pc.unrestrictedSearchResults(
                UID=content_id + '-' + language_info)
            if len(brains):
                obj.unrestrictedTraverse(
                    brains[0].getPath() + '/' + obj.id).reindexObject()
    return
示例#3
0
def is_shared_original(content):
    """
    Check if it's a shared real object
    """
    child = content
    for element in aq_chain(content):
        if IPloneSiteRoot.providedBy(element) and ILanguageRootFolder.providedBy(child):
            return False
    return True
示例#4
0
def is_shared(content):
    """ 
    Check if it's a ghost object
    """
    child = content
    for element in aq_chain(content):
        if hasattr(child, '_v_is_shared_content') and child._v_is_shared_content and ILanguageRootFolder.providedBy(element):
            return True
        child = element
    return False
示例#5
0
def get_original_object(content):
    """
    Get the original object of a shared content
    """
    path = []
    child = content

    for element in aq_chain(content):
        if hasattr(child, '_v_is_shared_content') and child._v_is_shared_content and ILanguageRootFolder.providedBy(element):
            break
        child = element
        path.insert(0, element.id)

    if ILanguageRootFolder.providedBy(element):
        # it's a ghost element
        site = getSite()
        return site.restrictedTraverse('/'.join(path))
    else:
        # It's the root element
        return content
示例#6
0
 def __call__(self, language):
     """
     Look for the closest translated folder or siteroot
     """
     parent = aq_parent(self.context)
     translated_parent = parent
     found = False
     while not (IPloneSiteRoot.providedBy(parent) and not ILanguageRootFolder.providedBy(parent)) and not found:
         parent_translation = ITranslationManager(parent)
         if parent_translation.has_translation(language):
             translated_parent = \
                 parent_translation.get_translation(language)
             found = True
         parent = aq_parent(parent)
     return translated_parent
示例#7
0
 def __call__(self, language):
     """
     Look for the closest translated folder or siteroot
     """
     parent = aq_parent(self.context)
     translated_parent = parent
     found = False
     while not (IPloneSiteRoot.providedBy(parent) and
                not ILanguageRootFolder.providedBy(parent))\
             and not found:
         parent_translation = ITranslationManager(parent)
         if parent_translation.has_translation(language):
             translated_parent =\
                 parent_translation.get_translation(language)
             found = True
         parent = aq_parent(parent)
     return translated_parent
def reindex_neutral(obj, event):
    """Neutral
    On shared elements, the uuid is different so we need to take care of
    them on catalog in case we modify any shared element
    """
    # is the given object Neutral?
    if IPloneSiteRoot.providedBy(obj) \
       or obj.getId() in BLACK_LIST_IDS \
       or (not is_shared(obj) and not is_shared_original(obj)):
        return

    parent = aq_parent(obj)
    if ILanguageRootFolder.providedBy(parent):
        # If it's parent is language root folder there is no need to reindex
        return

    site = getSite()
    language_tool = getToolByName(site, 'portal_languages')
    language_infos = language_tool.supported_langs
    if IPloneSiteRoot.providedBy(parent):
        # It's plone site root we need to look at LRF
        _reindex_site_root(obj, parent, language_infos)
        return

    # ok, we're very neutral
    content_id = IUUID(parent).split('-')[0]
    pc = getToolByName(site, 'portal_catalog')
    for language_info in language_infos:
        brains = pc.unrestrictedSearchResults(
            UID=content_id + '-' + language_info
        )
        if len(brains):
            # we have results, so parent was indexed before.
            brain = brains[0]
            obj.unrestrictedTraverse(
                brain.getPath() + '/' + obj.id).reindexObject()
    def getClosestDestination(self):
        """Get the "closest translated object" URL.
        """
        # We should travel the parent chain using the catalog here,
        # but I think using the acquisition chain is faster
        # (or well, __parent__ pointers) because the catalog
        # would require a lot of queries, while technically,
        # having done traversal up to this point you should
        # have the objects in memory already

        # As we don't have any content object we are going to look
        # for the best option

        site = getSite()
        root = getToolByName(site, 'portal_url')
        ltool = getToolByName(site, 'portal_languages')

        # We are using TranslationManager to get the translations of a
        # string tg
        manager = TranslationManager(self.tg)
        context = None
        languages = manager.get_translations()
        if len(languages) == 0:
            # If there is no results there are no translations
            # we move to portal root
            return self.wrapDestination(root(), postpath=False)

        # We are going to see if there is the preferred language translation
        # Otherwise we get the first as context to look for translation
        prefered = ltool.getPreferredLanguage(self.request)
        if prefered in languages:
            context = languages[prefered]
        else:
            context = languages[languages.keys()[0]]

        checkPermission = getSecurityManager().checkPermission
        chain = self.getParentChain(context)
        for item in chain:
            if ISiteRoot.providedBy(item) \
               and not ILanguageRootFolder.providedBy(item):
                # We do not care to get a permission error
                # if the whole of the portal cannot be viewed.
                # Having a permission issue on the root is fine;
                # not so much for everything else so that is checked there
                return self.wrapDestination(item.absolute_url())
            elif IFactoryTempFolder.providedBy(item) or \
                    IFactoryTool.providedBy(item):
                # TempFolder or portal_factory, can't have a translation
                continue
            try:
                canonical = ITranslationManager(item)
            except TypeError:
                if not ITranslatable.providedBy(item):
                    # In case there it's not translatable go to parent
                    # This solves the problem when a parent is not
                    # ITranslatable
                    continue
                else:
                    raise
            translation = canonical.get_translation(self.lang)
            if translation and (
                INavigationRoot.providedBy(translation) or
                bool(checkPermission('View', translation))
            ):
                # Not a direct translation, therefore no postpath
                # (the view might not exist on a different context)
                return self.wrapDestination(translation.absolute_url(),
                                            postpath=False)
        # Site root's the fallback
        return self.wrapDestination(root(), postpath=False)
示例#10
0
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form.
        """
        # Settings
        site_url = getSite().absolute_url()
        language_tool = getToolByName(context, "portal_languages")
        show_flags = language_tool.showFlags
        try:
            lang_names = request.locale.displayNames.languages
        except AttributeError:
            lang_names = {}

        registry = getUtility(IRegistry)
        settings = registry.forInterface(IMultiLanguageExtraOptionsSchema,
                                         prefix="plone")
        if settings.redirect_babel_view:
            translation_view = 'babel_edit'
        else:
            translation_view = 'edit'

        # Content
        content = context
        content_url = context.absolute_url()
        content_language = ILanguage(content).get_language()
        content_translatable = not (
            content_language == LANGUAGE_INDEPENDENT or
            is_language_independent(content) or
            ILanguageRootFolder.providedBy(content)
        )
        content_translated = translated_languages(content)
        content_untranslated = untranslated_languages(content)
        content_translation_group = ITG(content, '')
        if not ITranslatable.providedBy(content):
            content = None

        # Folder when content is default page
        folder = aq_parent(context)
        if not is_default_page(folder, context):
            folder = None
        if folder and ITranslatable.providedBy(folder):  # noqa
            folder_url = folder.absolute_url()
            folder_language = ILanguage(folder).get_language()
            folder_translatable = not (
                folder_language == LANGUAGE_INDEPENDENT or
                is_language_independent(folder) or
                ILanguageRootFolder.providedBy(folder)
            )
            folder_translated = translated_languages(folder)
            folder_untranslated = untranslated_languages(folder)
            folder_translation_group = ITG(folder, '')
        else:
            folder_url = ''
            folder_language = ''
            folder_translatable = False
            folder_translated = []
            folder_untranslated = []
            folder_translation_group = ''

        # Assets folder
        assets_folder_url = None
        assets_folder_title = None
        pc = getToolByName(getSite(), 'portal_catalog')
        results = pc.unrestrictedSearchResults(
            portal_type='LIF', Language=ILanguage(context).get_language())
        for brain in results:
            assets_folder_url = brain.getURL() + '/folder_contents'
            assets_folder_title = safe_unicode(brain.Title)
            break

        # Menu items
        results = []
        results_folder = []
        results_content = []

        if folder_translatable:
            # Folder translation view
            lang_name = lang_names.get(folder_language, folder_language)
            results_folder.append({
                "title": _(
                    u'edit_translation',
                    default=u"Edit ${lang_name}",
                    mapping={"lang_name": lang_name}
                ),
                "description": _(
                    u"description_babeledit_menu",
                    default=u"Edit {lang_name} with the two-column translation view",  # noqa
                    mapping={"lang_name": lang_name}
                ),
                "action": folder_url + "/" + translation_view,
                "selected": False,
                "icon": None,
                "extra": {
                    "id": "_edit_folder_babel_edit",
                    "separator": None,
                    "class": "",
                },
                "submenu": None,
            })

        if folder and folder_untranslated and False:  # disabled in favor of cut & paste  # noqa
            # Set folder language
            results_folder.append({
                "title": _(
                    u'title_set_language',
                    default=u"Change content language"
                ),
                "description": _(
                    u"description_set_language",
                    default=u"Move the translation under another language folder"  # noqa
                ),
                "action": folder_url + "/update_language",
                "selected": False,
                "icon": None,
                "extra": {
                    "id": "_set_folder_language",
                    "separator": None,
                    "class": ""
                },
                "submenu": None,
            })

        if folder_translatable:
            for idx, lang in enumerate(folder_untranslated):
                lang_name = lang_names.get(lang.value, lang.title)
                lang_id = lang.value
                icon = show_flags and language_tool.getFlagForLanguageCode(lang_id) or None  # noqa
                results_folder.append({
                    "title": _(
                        u'create_translation',
                        default=u"Create ${lang_name}",
                        mapping={"lang_name": lang_name}
                    ),
                    "description": _(
                        u"description_translate_into",
                        default=u"Translate into ${lang_name}",
                        mapping={"lang_name": lang_name}
                    ),
                    "action": "%s/@@create_translation?language=%s" % (
                        folder_url, lang_id),
                    "selected": False,
                    "icon": icon,
                    "width": "14",
                    "height": "11",
                    "extra": {"id": "translate_folder_into_%s" % lang_id,
                              "separator": None,
                              "class": "contentmenuflags"},
                    "submenu": None,

                })
            urls = translated_urls(folder)
            for lang in folder_translated:
                if lang.value not in urls.by_token:
                    # omit if translation is not permitted to access.
                    continue
                lang_name = lang_names.get(lang.value, lang.title)
                lang_id = lang.value
                icon = show_flags and language_tool.getFlagForLanguageCode(lang_id) or None  # noqa
                results_folder.append({
                    "title": _(
                        u'edit_translation',
                        default=u"Edit ${lang_name}",
                        mapping={"lang_name": lang_name}
                    ),
                    "description": _(
                        u"description_babeledit_menu",
                        default=u"Edit {lang_name} with the two-column translation view",  # noqa
                        mapping={"lang_name": lang_name}
                    ),
                    "action": (urls.getTerm(lang_id).title + "/" +
                               translation_view),
                    "selected": False,
                    "icon": icon,
                    "width": "14",
                    "height": "11",
                    "extra": {"id": "babel_edit_%s" % lang_id,
                              "separator": None,
                              "class": "contentmenuflags"},
                    "submenu": None,
                })
            # Manage folder translations
            results_folder.append({
                "title": _(
                    u"title_modify_translations",
                    default=u"Manage translations"
                ),
                "description": _(
                    u"description_modify_translations",
                    default=u"Add or delete translations"
                ),
                "action": folder_url + "/modify_translations",
                "selected": False,
                "icon": None,
                "extra": {
                    "id": "_modify_folder_translations",
                    "separator": None,
                    "class": ""
                },
                "submenu": None,
            })
            # Universal link
            if folder_translation_group:
                results_folder.append({
                    "title": _(
                        u"universal_link",
                        default=u"Universal link"
                    ),
                    "description": _(
                        u"description_universal_link",
                        default=u"Universal link to the content in user's preferred language"  # noqa
                    ),
                    "action": "%s/@@multilingual-universal-link/%s" % (
                        site_url, folder_translation_group),
                    "selected": False,
                    "icon": None,
                    "extra": {
                        "id": "_universal_folder_link",
                        "separator": None,
                        "class": ""
                    },
                    "submenu": None,
                })

        if results_folder:
            # Folder translation separator
            results.append({
                'title': _(
                    u'title_translate_current_folder',
                    default=u'Folder translation'
                ),
                'description': '',
                'action': None,
                'selected': False,
                'icon': None,
                'extra': {'id': 'translateFolderHeader',
                          'separator': 'actionSeparator',
                          'class': 'plone-toolbar-submenu-header'},
                'submenu': None,
            })
        results.extend(results_folder)

        lang_name = lang_names.get(content_language, content_language)

        # Content language
        if content_untranslated and False:  # disabled in favor of cut & paste
            results_content.append({
                "title": _(
                    u"title_set_language",
                    default=u"Change content language"
                ),
                "description": _(
                    u"description_set_language",
                    default=u"Move the translation under another language folder"  # noqa
                ),
                "action": content_url + "/update_language",
                "selected": False,
                "icon": None,
                "extra": {
                    "id": "_set_language",
                    "separator": None,
                    "class": ""
                },
                "submenu": None,
            })

        if content_translatable:
            # Content translation view
            results_content.append({
                "title": _(
                    u'edit_translation',
                    default=u"Edit ${lang_name}",
                    mapping={"lang_name": lang_name}
                ),
                "description": _(
                    u"description_babeledit_menu",
                    default=u"Edit {lang_name} with the two-column translation view",  # noqa
                    mapping={"lang_name": lang_name}
                ),
                "action": content_url + "/" + translation_view,
                "selected": False,
                "icon": None,
                "extra": {
                    "id": "_edit_babel_edit",
                    "separator": None,
                    "class": "",
                },
                "submenu": None,
            })

        if content_translatable:
            for idx, lang in enumerate(content_untranslated):
                lang_name = lang_names.get(lang.value, lang.title)
                lang_id = lang.value
                icon = show_flags and language_tool.getFlagForLanguageCode(lang_id) or None  # noqa
                results_content.append({
                    "title": _(
                        u'create_translation',
                        default=u"Create ${lang_name}",
                        mapping={"lang_name": lang_name}
                    ),
                    "description": _(
                        u"description_translate_into",
                        default=u"Translate into ${lang_name}",
                        mapping={"lang_name": lang_name}
                    ),
                    "action": "%s/@@create_translation?language=%s" % (
                        content_url, lang_id),
                    "selected": False,
                    "icon": icon,
                    "width": "14",
                    "height": "11",
                    "extra": {"id": "translate_into_%s" % lang_id,
                              "separator": None,
                              "class": "contentmenuflags"},
                    "submenu": None,

                })
            urls = translated_urls(content)
            for lang in content_translated:
                if lang.value not in urls.by_token:
                    # omit if translation is not permitted to access.
                    continue
                lang_name = lang_names.get(lang.value, lang.title)
                lang_id = lang.value
                icon = show_flags and language_tool.getFlagForLanguageCode(lang_id) or None  # noqa
                results_content.append({
                    "title": _(
                        u'edit_translation',
                        default=u"Edit ${lang_name}",
                        mapping={"lang_name": lang_name}
                    ),
                    "description": _(
                        u"description_babeledit_menu",
                        default=u"Edit {lang_name} with the two-column translation view",  # noqa
                        mapping={"lang_name": lang_name}
                    ),
                    "action": (urls.getTerm(lang_id).title + "/" +
                               translation_view),
                    "selected": False,
                    "icon": icon,
                    "width": "14",
                    "height": "11",
                    "extra": {"id": "babel_edit_%s" % lang_id,
                              "separator": None,
                              "class": "contentmenuflags"},
                    "submenu": None,
                })
            # Manage content translations
            results_content.append({
                "title": _(u"title_modify_translations",
                           default=u"Manage translations"),
                "description": _(
                    u"description_modify_translations",
                    default=u"Add or delete translations"
                ),
                "action": content_url + "/modify_translations",
                "selected": False,
                "icon": None,
                "extra": {
                    "id": "_modify_translations",
                    "separator": None,
                    "class": ""
                },
                "submenu": None,
            })
            # Universal link
            if content_translation_group:
                results_content.append({
                    "title": _(
                        u"universal_link",
                        default=u"Universal link"
                    ),
                    "description": _(
                        u"description_universal_link",
                        default=u"Universal link to the content in user's preferred language"  # noqa
                    ),
                    "action": "%s/@@multilingual-universal-link/%s" % (
                        site_url, content_translation_group),
                    "selected": False,
                    "icon": None,
                    "extra": {
                        "id": "_universal_link",
                        "separator": None,
                        "class": ""
                    },
                    "submenu": None,
                })

        if results_folder and results_content:
            # Item translations separator
            results.append({
                'title': _(
                    u'title_translate_current_item',
                    default=u'Item translation'
                ),
                'description': '',
                'action': None,
                'selected': False,
                'icon': None,
                'extra': {'id': 'translateItemHeader',
                          'separator': 'actionSeparator',
                          'class': ''},
                'submenu': None,
            })
        results.extend(results_content)

        # Language independent assets folder
        if assets_folder_url:
            results.append({
                "title": _(
                    u"shared_folder",
                    default=u"Open ${title} folder",
                    mapping={"title": assets_folder_title}
                ),
                "description": _(
                    u"description_shared_folder",
                    default=u"Open the language independent assets folder"
                ),
                "action": assets_folder_url,
                "selected": False,
                "icon": None,
                "extra": {
                    "id": "_shared_folder",
                    "separator": results and 'actionSeparator' or None,
                    "class": ""},
                "submenu": None,
            })

        # User preferred language root folder
        if not folder_translatable and not content_translatable:
            results.append({
                "title": _(
                    u"language_folder",
                    default=u"Return to language folder"
                ),
                "description": _(
                    u"description_language_folder",
                    default=u"Go to the user's browser preferred language "
                            u"related folder"
                ),
                "action": site_url + '/' + language_tool.getPreferredLanguage(),  # noqa
                "selected": False,
                "icon": None,
                "extra": {
                    "id": "_language_folder",
                    "separator": (
                        (results and not assets_folder_url) and
                        'actionSeparator' or None
                    ),
                    "class": ""
                },
                "submenu": None,
            })

        return results
示例#11
0
    def getClosestDestination(self):
        """Get the "closest translated object" URL.
        """
        # We should travel the parent chain using the catalog here,
        # but I think using the acquisition chain is faster
        # (or well, __parent__ pointers) because the catalog
        # would require a lot of queries, while technically,
        # having done traversal up to this point you should
        # have the objects in memory already

        # As we don't have any content object we are going to look
        # for the best option

        site = getSite()
        root = getToolByName(site, 'portal_url')
        ltool = getToolByName(site, 'portal_languages')

        # We are using TranslationManager to get the translations of a
        # string tg
        try:
            manager = TranslationManager(self.tg)
            languages = manager.get_translations()
        except AttributeError:
            languages = []
        if len(languages) == 0:
            # If there is no results there are no translations
            # we move to portal root
            return self.wrapDestination(root(), postpath=False)

        # We are going to see if there is the preferred language translation
        # Otherwise we get the first as context to look for translation
        prefered = ltool.getPreferredLanguage(self.request)
        if prefered in languages:
            context = languages[prefered]
        else:
            context = languages[list(languages.keys())[0]]

        checkPermission = getSecurityManager().checkPermission
        chain = self.getParentChain(context)
        for item in chain:
            if ISiteRoot.providedBy(item) \
               and not ILanguageRootFolder.providedBy(item):
                # We do not care to get a permission error
                # if the whole of the portal cannot be viewed.
                # Having a permission issue on the root is fine;
                # not so much for everything else so that is checked there
                return self.wrapDestination(item.absolute_url())
            elif IFactoryTempFolder.providedBy(item) or \
                    IFactoryTool.providedBy(item):
                # TempFolder or portal_factory, can't have a translation
                continue
            try:
                canonical = ITranslationManager(item)
            except TypeError:
                if not ITranslatable.providedBy(item):
                    # In case there it's not translatable go to parent
                    # This solves the problem when a parent is not
                    # ITranslatable
                    continue
                else:
                    raise
            translation = canonical.get_translation(self.lang)
            if translation and (INavigationRoot.providedBy(translation)
                                or bool(checkPermission('View', translation))):
                # Not a direct translation, therefore no postpath
                # (the view might not exist on a different context)
                return self.wrapDestination(translation.absolute_url(),
                                            postpath=False)
        # Site root's the fallback
        return self.wrapDestination(root(), postpath=False)
示例#12
0
 def _get_language_root_folder_path(self):
     for item in aq_chain(self.context):
         if ILanguageRootFolder.providedBy(item) or ISiteRoot.providedBy(
                 item):
             return "/".join(item.getPhysicalPath())
     return "/"
示例#13
0
    def getMenuItems(self, context, request):
        """Return menu item entries in a TAL-friendly form.
        """
        # Settings
        site_url = getSite().absolute_url()
        language_tool = getToolByName(context, "portal_languages")
        show_flags = language_tool.showFlags
        try:
            lang_names = request.locale.displayNames.languages
        except AttributeError:
            lang_names = {}

        registry = getUtility(IRegistry)
        settings = registry.forInterface(IMultiLanguageExtraOptionsSchema,
                                         prefix="plone")
        if settings.redirect_babel_view:
            translation_view = 'babel_edit'
        else:
            translation_view = 'edit'

        # Content
        content = context
        content_url = context.absolute_url()
        content_language = ILanguage(content).get_language()
        content_translatable = not (content_language == LANGUAGE_INDEPENDENT
                                    or is_language_independent(content)
                                    or ILanguageRootFolder.providedBy(content))
        content_translated = translated_languages(content)
        content_untranslated = untranslated_languages(content)
        content_translation_group = ITG(content, '')
        if not ITranslatable.providedBy(content):
            content = None

        # Folder when content is default page
        folder = aq_parent(context)
        if not is_default_page(folder, context):
            folder = None
        if folder and ITranslatable.providedBy(folder):  # noqa
            folder_url = folder.absolute_url()
            folder_language = ILanguage(folder).get_language()
            folder_translatable = not (folder_language == LANGUAGE_INDEPENDENT
                                       or is_language_independent(folder) or
                                       ILanguageRootFolder.providedBy(folder))
            folder_translated = translated_languages(folder)
            folder_untranslated = untranslated_languages(folder)
            folder_translation_group = ITG(folder, '')
        else:
            folder_url = ''
            folder_language = ''
            folder_translatable = False
            folder_translated = []
            folder_untranslated = []
            folder_translation_group = ''

        # Assets folder
        assets_folder_url = None
        assets_folder_title = None
        pc = getToolByName(getSite(), 'portal_catalog')
        results = pc.unrestrictedSearchResults(
            portal_type='LIF', Language=ILanguage(context).get_language())
        for brain in results:
            assets_folder_url = brain.getURL() + '/folder_contents'
            assets_folder_title = safe_unicode(brain.Title)
            break

        # Menu items
        results = []
        results_folder = []
        results_content = []

        if folder_translatable:
            # Folder translation view
            lang_name = lang_names.get(folder_language, folder_language)
            results_folder.append({
                "title":
                _(u'edit_translation',
                  default=u"Edit ${lang_name}",
                  mapping={"lang_name": lang_name}),
                "description":
                _(
                    u"description_babeledit_menu",
                    default=
                    u"Edit {lang_name} with the two-column translation view",  # noqa
                    mapping={"lang_name": lang_name}),
                "action":
                folder_url + "/" + translation_view,
                "selected":
                False,
                "icon":
                None,
                "extra": {
                    "id": "_edit_folder_babel_edit",
                    "separator": None,
                    "class": "",
                },
                "submenu":
                None,
            })

        if folder and folder_untranslated and False:  # disabled in favor of cut & paste  # noqa
            # Set folder language
            results_folder.append({
                "title":
                _(u'title_set_language', default=u"Change content language"),
                "description":
                _(
                    u"description_set_language",
                    default=
                    u"Move the translation under another language folder"  # noqa
                ),
                "action":
                folder_url + "/update_language",
                "selected":
                False,
                "icon":
                None,
                "extra": {
                    "id": "_set_folder_language",
                    "separator": None,
                    "class": ""
                },
                "submenu":
                None,
            })

        if folder_translatable:
            for idx, lang in enumerate(folder_untranslated):
                lang_name = lang_names.get(lang.value, lang.title)
                lang_id = lang.value
                icon = show_flags and language_tool.getFlagForLanguageCode(
                    lang_id) or None  # noqa
                results_folder.append({
                    "title":
                    _(u'create_translation',
                      default=u"Create ${lang_name}",
                      mapping={"lang_name": lang_name}),
                    "description":
                    _(u"description_translate_into",
                      default=u"Translate into ${lang_name}",
                      mapping={"lang_name": lang_name}),
                    "action":
                    "%s/@@create_translation?language=%s" %
                    (folder_url, lang_id),
                    "selected":
                    False,
                    "icon":
                    icon,
                    "width":
                    "14",
                    "height":
                    "11",
                    "extra": {
                        "id": "translate_folder_into_%s" % lang_id,
                        "separator": None,
                        "class": "contentmenuflags"
                    },
                    "submenu":
                    None,
                })
            urls = translated_urls(folder)
            for lang in folder_translated:
                if lang.value not in urls.by_token:
                    # omit if translation is not permitted to access.
                    continue
                lang_name = lang_names.get(lang.value, lang.title)
                lang_id = lang.value
                icon = show_flags and language_tool.getFlagForLanguageCode(
                    lang_id) or None  # noqa
                results_folder.append({
                    "title":
                    _(u'edit_translation',
                      default=u"Edit ${lang_name}",
                      mapping={"lang_name": lang_name}),
                    "description":
                    _(
                        u"description_babeledit_menu",
                        default=
                        u"Edit {lang_name} with the two-column translation view",  # noqa
                        mapping={"lang_name": lang_name}),
                    "action":
                    (urls.getTerm(lang_id).title + "/" + translation_view),
                    "selected":
                    False,
                    "icon":
                    icon,
                    "width":
                    "14",
                    "height":
                    "11",
                    "extra": {
                        "id": "babel_edit_%s" % lang_id,
                        "separator": None,
                        "class": "contentmenuflags"
                    },
                    "submenu":
                    None,
                })
            # Manage folder translations
            results_folder.append({
                "title":
                _(u"title_modify_translations",
                  default=u"Manage translations"),
                "description":
                _(u"description_modify_translations",
                  default=u"Add or delete translations"),
                "action":
                folder_url + "/modify_translations",
                "selected":
                False,
                "icon":
                None,
                "extra": {
                    "id": "_modify_folder_translations",
                    "separator": None,
                    "class": ""
                },
                "submenu":
                None,
            })
            # Universal link
            if folder_translation_group:
                results_folder.append({
                    "title":
                    _(u"universal_link", default=u"Universal link"),
                    "description":
                    _(
                        u"description_universal_link",
                        default=
                        u"Universal link to the content in user's preferred language"  # noqa
                    ),
                    "action":
                    "%s/@@multilingual-universal-link/%s" %
                    (site_url, folder_translation_group),
                    "selected":
                    False,
                    "icon":
                    None,
                    "extra": {
                        "id": "_universal_folder_link",
                        "separator": None,
                        "class": ""
                    },
                    "submenu":
                    None,
                })

        if results_folder:
            # Folder translation separator
            results.append({
                'title':
                _(u'title_translate_current_folder',
                  default=u'Folder translation'),
                'description':
                '',
                'action':
                None,
                'selected':
                False,
                'icon':
                None,
                'extra': {
                    'id': 'translateFolderHeader',
                    'separator': 'actionSeparator',
                    'class': 'plone-toolbar-submenu-header'
                },
                'submenu':
                None,
            })
        results.extend(results_folder)

        lang_name = lang_names.get(content_language, content_language)

        # Content language
        if content_untranslated and False:  # disabled in favor of cut & paste
            results_content.append({
                "title":
                _(u"title_set_language", default=u"Change content language"),
                "description":
                _(
                    u"description_set_language",
                    default=
                    u"Move the translation under another language folder"  # noqa
                ),
                "action":
                content_url + "/update_language",
                "selected":
                False,
                "icon":
                None,
                "extra": {
                    "id": "_set_language",
                    "separator": None,
                    "class": ""
                },
                "submenu":
                None,
            })

        if content_translatable:
            # Content translation view
            results_content.append({
                "title":
                _(u'edit_translation',
                  default=u"Edit ${lang_name}",
                  mapping={"lang_name": lang_name}),
                "description":
                _(
                    u"description_babeledit_menu",
                    default=
                    u"Edit {lang_name} with the two-column translation view",  # noqa
                    mapping={"lang_name": lang_name}),
                "action":
                content_url + "/" + translation_view,
                "selected":
                False,
                "icon":
                None,
                "extra": {
                    "id": "_edit_babel_edit",
                    "separator": None,
                    "class": "",
                },
                "submenu":
                None,
            })

        if content_translatable:
            for idx, lang in enumerate(content_untranslated):
                lang_name = lang_names.get(lang.value, lang.title)
                lang_id = lang.value
                icon = show_flags and language_tool.getFlagForLanguageCode(
                    lang_id) or None  # noqa
                results_content.append({
                    "title":
                    _(u'create_translation',
                      default=u"Create ${lang_name}",
                      mapping={"lang_name": lang_name}),
                    "description":
                    _(u"description_translate_into",
                      default=u"Translate into ${lang_name}",
                      mapping={"lang_name": lang_name}),
                    "action":
                    "%s/@@create_translation?language=%s" %
                    (content_url, lang_id),
                    "selected":
                    False,
                    "icon":
                    icon,
                    "width":
                    "14",
                    "height":
                    "11",
                    "extra": {
                        "id": "translate_into_%s" % lang_id,
                        "separator": None,
                        "class": "contentmenuflags"
                    },
                    "submenu":
                    None,
                })
            urls = translated_urls(content)
            for lang in content_translated:
                if lang.value not in urls.by_token:
                    # omit if translation is not permitted to access.
                    continue
                lang_name = lang_names.get(lang.value, lang.title)
                lang_id = lang.value
                icon = show_flags and language_tool.getFlagForLanguageCode(
                    lang_id) or None  # noqa
                results_content.append({
                    "title":
                    _(u'edit_translation',
                      default=u"Edit ${lang_name}",
                      mapping={"lang_name": lang_name}),
                    "description":
                    _(
                        u"description_babeledit_menu",
                        default=
                        u"Edit {lang_name} with the two-column translation view",  # noqa
                        mapping={"lang_name": lang_name}),
                    "action":
                    (urls.getTerm(lang_id).title + "/" + translation_view),
                    "selected":
                    False,
                    "icon":
                    icon,
                    "width":
                    "14",
                    "height":
                    "11",
                    "extra": {
                        "id": "babel_edit_%s" % lang_id,
                        "separator": None,
                        "class": "contentmenuflags"
                    },
                    "submenu":
                    None,
                })
            # Manage content translations
            results_content.append({
                "title":
                _(u"title_modify_translations",
                  default=u"Manage translations"),
                "description":
                _(u"description_modify_translations",
                  default=u"Add or delete translations"),
                "action":
                content_url + "/modify_translations",
                "selected":
                False,
                "icon":
                None,
                "extra": {
                    "id": "_modify_translations",
                    "separator": None,
                    "class": ""
                },
                "submenu":
                None,
            })
            # Universal link
            if content_translation_group:
                results_content.append({
                    "title":
                    _(u"universal_link", default=u"Universal link"),
                    "description":
                    _(
                        u"description_universal_link",
                        default=
                        u"Universal link to the content in user's preferred language"  # noqa
                    ),
                    "action":
                    "%s/@@multilingual-universal-link/%s" %
                    (site_url, content_translation_group),
                    "selected":
                    False,
                    "icon":
                    None,
                    "extra": {
                        "id": "_universal_link",
                        "separator": None,
                        "class": ""
                    },
                    "submenu":
                    None,
                })

        if results_folder and results_content:
            # Item translations separator
            results.append({
                'title':
                _(u'title_translate_current_item',
                  default=u'Item translation'),
                'description':
                '',
                'action':
                None,
                'selected':
                False,
                'icon':
                None,
                'extra': {
                    'id': 'translateItemHeader',
                    'separator': 'actionSeparator',
                    'class': ''
                },
                'submenu':
                None,
            })
        results.extend(results_content)

        # Language independent assets folder
        if assets_folder_url:
            results.append({
                "title":
                _(u"shared_folder",
                  default=u"Open ${title} folder",
                  mapping={"title": assets_folder_title}),
                "description":
                _(u"description_shared_folder",
                  default=u"Open the language independent assets folder"),
                "action":
                assets_folder_url,
                "selected":
                False,
                "icon":
                None,
                "extra": {
                    "id": "_shared_folder",
                    "separator": results and 'actionSeparator' or None,
                    "class": ""
                },
                "submenu":
                None,
            })

        # User preferred language root folder
        if not folder_translatable and not content_translatable:
            results.append({
                "title":
                _(u"language_folder", default=u"Return to language folder"),
                "description":
                _(u"description_language_folder",
                  default=u"Go to the user's browser preferred language "
                  u"related folder"),
                "action":
                site_url + '/' + language_tool.getPreferredLanguage(),  # noqa
                "selected":
                False,
                "icon":
                None,
                "extra": {
                    "id":
                    "_language_folder",
                    "separator":
                    ((results and not assets_folder_url) and 'actionSeparator'
                     or None),
                    "class":
                    ""
                },
                "submenu":
                None,
            })

        return results