Esempio n. 1
0
    def __call__(self, expand=False):
        result = {
            "translations": {
                "@id": f"{self.context.absolute_url()}/@translations"
            }
        }
        if not expand:
            return result

        translations = []
        manager = ITranslationManager(self.context)
        for language, translation in manager.get_restricted_translations(
        ).items():
            if language != ILanguage(self.context).get_language():
                translations.append({
                    "@id": translation.absolute_url(),
                    "language": language
                })

        portal_state = getMultiAdapter((self.context, self.request),
                                       name="plone_portal_state")
        current_lang_nav_root = portal_state.navigation_root()

        if IPloneSiteRoot.providedBy(current_lang_nav_root):
            # We are not inside a LRF, bail off
            return result

        nav_root_manager = ITranslationManager(current_lang_nav_root)
        nav_root_translations = {}
        for (
                language,
                translation,
        ) in nav_root_manager.get_restricted_translations().items():
            nav_root_translations[language] = translation.absolute_url()

        result["translations"]["items"] = translations
        result["translations"]["root"] = nav_root_translations
        return result
Esempio n. 2
0
    def __call__(self, expand=False):
        result = {
            "translations": {
                "@id": "{}/@translations".format(self.context.absolute_url())
            }
        }
        if not expand:
            return result

        translations = []
        manager = ITranslationManager(self.context)
        for language, translation in manager.get_restricted_translations(
        ).items():
            if language != ILanguage(self.context).get_language():
                translations.append({
                    "@id": translation.absolute_url(),
                    "language": language
                })

        result["translations"]["items"] = translations
        return result