当前位置: 首页>>代码示例>>Python>>正文


Python interfaces.ITranslationManager类代码示例

本文整理汇总了Python中plone.app.multilingual.interfaces.ITranslationManager的典型用法代码示例。如果您正苦于以下问题:Python ITranslationManager类的具体用法?Python ITranslationManager怎么用?Python ITranslationManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ITranslationManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_all_translations

 def get_all_translations(self, content):
     """Return all translations excluding the just modified content"""
     content_lang = queryAdapter(content, ILanguage).get_language()
     translations = ITranslationManager(content).get_translated_languages()
     while content_lang in translations:
         translations.remove(content_lang)
     return translations
开发者ID:plone,项目名称:plone.app.multilingual,代码行数:7,代码来源:subscriber.py

示例2: setContentsInActionMenu

 def setContentsInActionMenu(self, value):
     self.settings.contents_in_action_menu = value
     portal = root = api.portal.get()
     if 'fr' in root.objectIds():
         fr = getattr(root, 'fr')
         root = api.portal.get_navigation_root(fr)
     catalog = api.portal.get_tool('portal_catalog')
     name = 'cpskin.core.vocabularies.action_menu_eligible'
     factory = getUtility(IVocabularyFactory, name)
     vocabulary = factory(portal)
     all_values = vocabulary.by_value.keys()
     for content_id in all_values:
         content = getattr(root, content_id, None)
         if not content:
             continue
         translations = {'fr': content}
         request = getattr(self.context, 'REQUEST', None)
         if is_plone_app_multilingual_installed(request):
             translations = ITranslationManager(content).get_translations()
         if content_id in value:
             for t in translations.values():
                 if IElectedContentForTopMenu.providedBy(t):
                     continue
                 alsoProvides(t, IElectedContentForTopMenu)
                 catalog.reindexObject(t)
         else:
             for t in translations.values():
                 if not IElectedContentForTopMenu.providedBy(t):
                     continue
                 noLongerProvides(t, IElectedContentForTopMenu)
                 catalog.reindexObject(t)
开发者ID:IMIO,项目名称:cpskin.core,代码行数:31,代码来源:controlpanel.py

示例3: __call__

    def __call__(self):
        pc = getToolByName(self.context, 'portal_catalog')
        pl = getToolByName(self.context, 'portal_languages')
        self.results = []
        for language_supported in pl.getSupportedLanguages():
            translated_objects = pc.searchResults(
                object_provides=LP_TRANSLATABLE,
                Language=language_supported)
            for brain in translated_objects:
                obj = brain.getObject()
                if obj.isCanonical():
                    translations = obj.getTranslations(include_canonical=False)
                    manager = ITranslationManager(obj)
                    if translations:
                        for language in translations.keys():
                            try:
                                manager.register_translation(
                                    language, translations[language][0])
                            except KeyError:
                                logger.info(
                                    '%s already translated to %s: %s' %
                                    (obj.id, language,
                                        str(manager.get_translations())))

                        self.results.append(str(manager.get_translations()))

        logger.info('Finished with transferring catalog information')
        return self.template()
开发者ID:plone,项目名称:plone.app.multilingual,代码行数:28,代码来源:migrator.py

示例4: __call__

    def __call__(self):
        language = self.request.get('language', None)
        if language:
            context = aq_inner(self.context)
            translation_manager = ITranslationManager(context)
            # if ILanguage(context).get_language() == LANGUAGE_INDEPENDENT:
            #     # XXX : Why we need this ? the subscriber from pm should
            #             maintain it
            #     language_tool = getToolByName(context, 'portal_languages')
            #     default_language = language_tool.getDefaultLanguage()
            #     ILanguage(context).set_language(default_language)
            #     translation_manager.update()
            #     context.reindexObject()

            new_parent = translation_manager.add_translation_delegated(language)  # noqa

            registry = getUtility(IRegistry)
            settings = registry.forInterface(IMultiLanguageExtraOptionsSchema)
            sdm = self.context.session_data_manager
            session = sdm.getSessionData(create=True)
            session.set("tg", translation_manager.tg)
            session.set("old_lang", ILanguage(self.context).get_language())

            baseUrl = new_parent.absolute_url()
            # We set the language and redirect to babel_view or not
            if settings.redirect_babel_view:
                # Call the ++addtranslation++ adapter to show the babel
                # add form
                url = '%s/++addtranslation++%s' % (
                    baseUrl, self.context.portal_type)
                return self.request.response.redirect(url)
            else:
                # We look for the creation url for this content type

                # Get the factory
                types_tool = getToolByName(self.context, 'portal_types')

                # Note: we don't check 'allowed' or 'available' here,
                # because these are slow. We assume the 'allowedTypes'
                # list has already performed the necessary calculations
                actions = types_tool.listActionInfos(
                    object=new_parent,
                    check_permissions=False,
                    check_condition=False,
                    category='folder/add',
                )

                addActionsById = dict([(a['id'], a) for a in actions])

                typeId = self.context.portal_type

                addAction = addActionsById.get(typeId, None)

                if addAction is not None:
                    url = addAction['url']

                if not url:
                    url = '%s/createObject?type_name=%s' % (
                        baseUrl, quote_plus(typeId))
                return self.request.response.redirect(url)
开发者ID:jianaijun,项目名称:plone.app.multilingual,代码行数:60,代码来源:translate.py

示例5: handle_modified

    def handle_modified(self, content):

        fieldmanager = ILanguageIndependentFieldsManager(content)
        if not fieldmanager.has_independent_fields():
            return

        sm = getSecurityManager()
        try:
            # Do we have permission to sync language independent fields?
            if self.bypass_security_checks():
                # Clone the current user and assign a new editor role to
                # allow edition of all translated objects even if the
                # current user whould not have permission to do that.
                tmp_user = UnrestrictedUser(
                    sm.getUser().getId(), '', ['Editor', ], '')

                # Wrap the user in the acquisition context of the portal
                # and finally switch the user to our new editor
                acl_users = getToolByName(content, 'acl_users')
                tmp_user = tmp_user.__of__(acl_users)
                newSecurityManager(None, tmp_user)

            # Copy over all language independent fields
            transmanager = ITranslationManager(content)
            for translation in self.get_all_translations(content):
                trans_obj = transmanager.get_translation(translation)
                if fieldmanager.copy_fields(trans_obj):
                    self.reindex_translation(trans_obj)
        finally:
            # Restore the old security manager
            setSecurityManager(sm)
开发者ID:martior,项目名称:plone.app.multilingual,代码行数:31,代码来源:subscriber.py

示例6: test_add_translation_delegated

    def test_add_translation_delegated(self):
        a_ca = createContentInContainer(
            self.portal['ca'], 'Document', title=u"Test document")

        translation_manager = ITranslationManager(a_ca)
        portal_es = translation_manager.add_translation_delegated('es')

        self.assertEqual(portal_es, self.portal['es'])
开发者ID:jianaijun,项目名称:plone.app.multilingual,代码行数:8,代码来源:test_api.py

示例7: handle_unlink

    def handle_unlink(self, action):
        data, errors = self.extractData()
        manager = ITranslationManager(self.context)
        if not errors:
            for language in data['languages']:
                manager.remove_translation(language)

        return self.request.response.redirect(
            self.context.absolute_url() + '/remove_translations')
开发者ID:AnneGilles,项目名称:plone.app.multilingual,代码行数:9,代码来源:remove.py

示例8: __call__

 def __call__(self):
     language = self.request.get('language', None)
     if language:
         context = aq_inner(self.context)
         translation_manager = ITranslationManager(context)
         new_parent = translation_manager.add_translation_delegated(language)  # noqa
         baseUrl = new_parent.absolute_url()
         url = '%s/++addtranslation++%s' % (baseUrl, IUUID(context))
         return self.request.response.redirect(url)
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:9,代码来源:translate.py

示例9: __init__

 def __init__(self, context, request):
     super(BabelUtils, self).__init__(context, request)
     portal_state = getMultiAdapter((context, request),
                                    name="plone_portal_state")
     self.portal_url = portal_state.portal_url()
     # If there is any translation_info lets use it
     try:
         self.group = TranslationManager(request.translation_info['tg'])
     except AttributeError:
         self.group = ITranslationManager(self.context)
开发者ID:albertduran,项目名称:plone.app.multilingual,代码行数:10,代码来源:utils.py

示例10: handle_remove

    def handle_remove(self, action):
        data, errors = self.extractData()
        manager = ITranslationManager(self.context)
        if not errors:
            for language in data['languages']:
                content = manager.get_translation(language)
                manager.remove_translation(language)
                aq_parent(content).manage_delObjects([content.getId()])

        return self.request.response.redirect(
            self.context.absolute_url() + '/remove_translations')
开发者ID:AnneGilles,项目名称:plone.app.multilingual,代码行数:11,代码来源:remove.py

示例11: get_all_translations

    def get_all_translations(self, content):
        """Return all translations excluding the just modified content"""
        translations_list_to_process = []
        content_lang = queryAdapter(content, ILanguage).get_language()
        canonical = ITranslationManager(content)
        translations = canonical.get_translations()

        for language in translations.keys():
            if language != content_lang:
                translations_list_to_process.append(translations[language])
        return translations_list_to_process
开发者ID:naro,项目名称:archetypes.multilingual,代码行数:11,代码来源:subscriber.py

示例12: test_multilingual_content_is_linked

    def test_multilingual_content_is_linked(self):
        english_content = self.portal.get('en').get('accessibility')
        self.assertIsNotNone(english_content, 'Missing page /en/accessibility')

        german_content = self.portal.get('de').get('barrierefreiheit')
        self.assertIsNotNone(german_content,
                             'Missing page /de/barrierefreiheit')

        manager = ITranslationManager(english_content)
        self.assertEquals(german_content,
                          manager.get_translation('de'),
                          'English and German content should be linked.')
开发者ID:erral,项目名称:ftw.inflator,代码行数:12,代码来源:test_multilingual_content_creation.py

示例13: __init__

 def __init__(self, context, request):
     super(BabelUtils, self).__init__(context, request)
     portal_state = getMultiAdapter((context, request),
                                    name="plone_portal_state")
     self.portal_url = portal_state.portal_url()
     # If there is any session tg lets use the session tg
     sdm = self.context.session_data_manager
     session = sdm.getSessionData(create=True)
     if 'tg' in session.keys():
         self.group = TranslationManager(session['tg'])
     else:
         self.group = ITranslationManager(self.context)
开发者ID:quintagroup,项目名称:plone.app.multilingual,代码行数:12,代码来源:utils.py

示例14: link_translations

def link_translations(items):
    """
        Links the translations with the declared items with the form:
        [(obj1, lang1), (obj2, lang2), ...] assuming that the first element
        is the 'canonical' (in PAM there is no such thing).
    """
    # Grab the first item object and get its canonical handler
    canonical = ITranslationManager(items[0][0])

    for obj, language in items:
        if not canonical.has_translation(language):
            canonical.register_translation(language, obj)
开发者ID:UPCnet,项目名称:genweb.core,代码行数:12,代码来源:utils.py

示例15: deletable_languages

def deletable_languages(context):
    manager = ITranslationManager(context)
    translated_languages = manager.get_translated_languages()
    language_tool = getToolByName(context, "portal_languages")
    language_infos = language_tool.getAvailableLanguages()
    content_language = ILanguage(context).get_language()
    languages = []
    for lang in translated_languages:
        if lang not in content_language:
            native = language_infos[lang].get("native", None)
            name = language_infos[lang].get("name", lang)
            languages.append(SimpleVocabulary.createTerm(lang, lang, native or name))
    return SimpleVocabulary(languages)
开发者ID:khink,项目名称:plone.app.multilingual,代码行数:13,代码来源:vocabularies.py


注:本文中的plone.app.multilingual.interfaces.ITranslationManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。