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


Python interfaces.ITranslatable类代码示例

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


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

示例1: __init__

    def __init__(self, context, request, view, manager):
        super(CookiePolicyViewlet, self).__init__(context, request, view,
                                                  manager)
        registry = getUtility(IRegistry)
        self.proxy = registry.forInterface(ICookiePolicySchema)

        if self.proxy:
            self.enabled = self.proxy.enabled
            self.cookies_document_id = self.proxy.cookies_document_id
            portal = api.portal.get()
            try:
                cookies_document = portal.restrictedTraverse(str(self.cookies_document_id))
            except:
                cookies_document = None
            if cookies_document:
                if multilingual_enabled:
                    try:
                        language = ILanguage(context).get_language()
                    except:
                        language = "en"
                    try:
                        if ITranslatable.providedBy(cookies_document):
                            cookies_document_translated=ITranslationManager(cookies_document).get_translation(language)
                            if cookies_document_translated:
                               cookies_document=cookies_document_translated
                    except:
                        pass
                self.title = cookies_document.description
                self.message = cookies_document.text.output
开发者ID:dmunicio,项目名称:tlspu.cookiepolicy,代码行数:29,代码来源:viewlets.py

示例2: update

 def update(self):
     """ It's only for AT on factory so we check """
     if self.context.portal_factory.isTemporary(self.context):
         if ITranslatable.providedBy(self.context):
             self.lang = ILanguage(self.context).get_language()
         else:
             self.lang = 'NaN'
开发者ID:naro,项目名称:archetypes.multilingual,代码行数:7,代码来源:viewlets.py

示例3: is_translatable

def is_translatable(content):
    """Checks if content is translatable.

    :param content: Content to be translated.
    :type content: Content object
    :returns: Boolean
    """
    return ITranslatable.providedBy(content)
开发者ID:AnneGilles,项目名称:plone.app.multilingual,代码行数:8,代码来源:api.py

示例4: get_translations

    def get_translations(self):
        cts = []
        if ITranslatable.providedBy(self.context):
            t_langs = translated_languages(self.context)
            context_translations = ITranslationManager(self.context).get_translations()
            for lang in t_langs:
                cts.append(dict(lang_native=lang.title,
                                url=context_translations[lang.value].absolute_url()))

        return cts
开发者ID:zopyx,项目名称:plone.app.layout,代码行数:10,代码来源:content.py

示例5: set_default_language_content

 def set_default_language_content(self):
     """
     Set default language on root to language independent
     """
     portal = getSite()
     defaultLanguage = LANGUAGE_INDEPENDENT
     for id in portal.objectIds():
         if id not in _languagelist and \
            id not in _combinedlanguagelist and \
            ITranslatable.providedBy(portal[id]):
             set_recursive_language(portal[id], defaultLanguage)
开发者ID:fredvd,项目名称:plone.app.multilingual,代码行数:11,代码来源:setup.py

示例6: _update_deferred

    def _update_deferred(self):
        for path, canonicalpath, language in self.deferred:
            obj = self._traverse(path)
            if obj is None:
                continue
            canonical = self._traverse(canonicalpath)
            if canonical is None:
                continue

            if (ITranslatable.providedBy(obj) and
                    ITranslatable.providedBy(canonical)):
                try:
                    translation_group = IMutableTG(canonical).get()
                    IMutableTG(obj).set(translation_group)
                    manager = ITranslationManager(obj)
                    manager.register_translation(language, obj)
                except KeyError:
                    # put obj in a separate translation group when registration
                    # fails
                    IMutableTG(obj).set(self.uuid_generator())
开发者ID:erral,项目名称:ftw.blueprints,代码行数:20,代码来源:multilingual.py

示例7: set_recursive_language

def set_recursive_language(obj, language):
    """ Set the language at this object and recursive
    """
    if ILanguage(obj).get_language() != language:
        ILanguage(obj).set_language(language)
        ITranslationManager(obj).update()
        reindex_object(obj)
    if IFolderish.providedBy(obj):
        for item in obj.items():
            if ITranslatable.providedBy(item):
                set_recursive_language(item, language)
开发者ID:quintagroup,项目名称:plone.app.multilingual,代码行数:11,代码来源:subscriber.py

示例8: update

 def update(self):
     try:
         tg = self.request.translation_info['tg']
     except AttributeError:
         return
     self.available = True
     if ITranslatable.providedBy(self.context):
         self.lang = ILanguage(self.context).get_language()
     else:
         self.lang = 'NaN'
     catalog = getToolByName(self.context, 'portal_catalog')
     query = {'TranslationGroup': tg, 'Language': 'all'}
     self.origin = catalog.searchResults(query)
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:13,代码来源:viewlets.py

示例9: createdEvent

def createdEvent(obj, event):
    """ Subscriber to set language on the child folder

    It can be a
    - IObjectRemovedEvent - don't do anything
    - IObjectMovedEvent
    - IObjectAddedEvent
    - IObjectCopiedEvent
    """
    if IObjectRemovedEvent.providedBy(event):
        return

    request = getattr(event.object, 'REQUEST', getRequest())
    if not IPloneAppMultilingualInstalled.providedBy(request):
        return

    # On ObjectCopiedEvent and ObjectMovedEvent aq_parent(event.object) is
    # always equal to event.newParent.
    parent = aq_parent(event.object)

    # special parent handling
    if not ITranslatable.providedBy(parent):
        set_recursive_language(obj, LANGUAGE_INDEPENDENT)
        return

    # Normal use case
    # We set the tg, linking
    language = ILanguage(parent).get_language()
    set_recursive_language(obj, language)

    request = getattr(event.object, 'REQUEST', getRequest())
    try:
        ti = request.translation_info
    except AttributeError:
        return

    # AT check
    portal = getSite()
    portal_factory = getToolByName(portal, 'portal_factory', None)
    if (
        not IDexterityContent.providedBy(obj)
        and portal_factory is not None
        and not portal_factory.isTemporary(obj)
    ):
        return

    IMutableTG(obj).set(ti['tg'])
    modified(obj)
    tm = ITranslationManager(obj)
    old_obj = tm.get_translation(ti['source_language'])
    ILanguageIndependentFieldsManager(old_obj).copy_fields(obj)
开发者ID:AnneGilles,项目名称:plone.app.multilingual,代码行数:51,代码来源:subscriber.py

示例10: update

 def update(self):
     sdm = self.context.session_data_manager
     session = sdm.getSessionData(create=True)
     if ITranslatable.providedBy(self.context):
         self.lang = ILanguage(self.context).get_language()
     else:
         self.lang = 'NaN'
     if 'tg' in session.keys():
         tg = session['tg']
         self.available = True
         ptool = getToolByName(self.context, 'portal_catalog')
         query = {'TranslationGroup': tg, 'Language': 'all'}
         results = ptool.searchResults(query)
         self.origin = results
开发者ID:fredvd,项目名称:plone.app.multilingual,代码行数:14,代码来源:viewlets.py

示例11: set_recursive_language

def set_recursive_language(ob, language):
    """Set the language for this object and its children in a recursive
    manner

    """
    if is_language_independent(ob):
        ILanguage(ob).set_language(None)

    elif ILanguage(ob).get_language() != language:
        ILanguage(ob).set_language(language)
        ITranslationManager(ob).update()
        reindex_object(ob)

    for child in (IFolderish.providedBy(ob) and ob.items() or ()):
        if ITranslatable.providedBy(child):
            set_recursive_language(child, language)
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:16,代码来源:subscriber.py

示例12: update

 def update(self):
     """ It's only for AT on factory so we check """
     factory = getToolByName(self.context, 'portal_factory', None)
     if factory is not None and factory.isTemporary(self.context):
         sdm = self.context.session_data_manager
         session = sdm.getSessionData(create=True)
         if ITranslatable.providedBy(self.context):
             self.lang = ILanguage(self.context).get_language()
         else:
             self.lang = 'NaN'
         if 'tg' in session.keys():
             tg = session['tg']
             self.available = True
             ptool = getToolByName(self.context, 'portal_catalog')
             query = {'TranslationGroup': tg, 'Language': 'all'}
             results = ptool.searchResults(query)
             self.origin = results
开发者ID:jianaijun,项目名称:plone.app.multilingual,代码行数:17,代码来源:viewlets.py

示例13: createdEvent

def createdEvent(obj, event):
    """ It can be a
        IObjectRemovedEvent - don't do anything
        IObjectMovedEvent
        IObjectAddedEvent
        IObjectCopiedEvent
    """
    if IObjectRemovedEvent.providedBy(event):
        return

    # On ObjectCopiedEvent and ObjectMovedEvent aq_parent(event.object) is
    # always equal to event.newParent.
    parent = aq_parent(event.object)

    if ITranslatable.providedBy(parent):
        # Normal use case
        # We set the tg, linking
        language = ILanguage(parent).get_language()
        set_recursive_language(obj, language)
        sdm = obj.session_data_manager
        session = sdm.getSessionData()
        portal = getSite()
        portal_factory = getToolByName(portal, 'portal_factory', None)

        request = getattr(event.object, 'REQUEST', getRequest())
        has_pam_old_lang_in_form = (
            request and
            'form.widgets.pam_old_lang' not in request.form
        )
        if (not has_pam_old_lang_in_form
                and 'tg' in session.keys()
                and 'old_lang' in session.keys()
                and (portal_factory is None
                     or not portal_factory.isTemporary(obj))):
            IMutableTG(obj).set(session['tg'])
            modified(obj)
            del session['tg']
            old_obj = ITranslationManager(obj)\
                .get_translation(session['old_lang'])
            ILanguageIndependentFieldsManager(old_obj).copy_fields(obj)
            del session['old_lang']
    else:
        set_recursive_language(obj, LANGUAGE_INDEPENDENT)
开发者ID:jianaijun,项目名称:plone.app.multilingual,代码行数:43,代码来源:subscriber.py

示例14: __iter__

    def __iter__(self):
        for item in self.previous:
            pathkey = self.pathkey(*item.keys())[0]
            if not pathkey:
                yield item
                continue

            path = item[pathkey]
            if isinstance(path, unicode):
                path = path.encode('ascii')

            obj = self._traverse(path)
            if obj is None:
                yield item
                continue

            canonicalkey = self.canonicalkey(*item.keys())[0]
            translationkey = self.translationkey(*item.keys())[0]

            if not canonicalkey:
                yield item
                continue

            canonicalpath = item[translationkey]
            if isinstance(canonicalpath, unicode):
                canonicalpath = canonicalpath.encode('ascii')
            language = item['language']
            if ITranslatable.providedBy(obj):
                ILanguage(obj).set_language(language)
            if item[canonicalkey]:
                IMutableTG(obj).set(self.uuid_generator())
                manager = ITranslationManager(obj)
                manager.register_translation(language, obj)
            else:
                self.deferred.append((path, canonicalpath, language))
            yield item

        self._update_deferred()
开发者ID:4teamwork,项目名称:ftw.blueprints,代码行数:38,代码来源:multilingual.py

示例15: createdEvent

def createdEvent(obj, event):
    """ It can be a
        IObjectRemovedEvent - don't do anything
        IObjectMovedEvent
        IObjectAddedEvent
        IObjectCopiedEvent
    """
    if IObjectRemovedEvent.providedBy(event):
        return

    portal = getSite()

    # On ObjectCopiedEvent and ObjectMovedEvent aq_parent(event.object) is
    # always equal to event.newParent.
    parent = aq_parent(event.object)

    if ITranslatable.providedBy(parent):
        # Normal use case
        # We set the tg, linking
        language = ILanguage(parent).get_language()
        set_recursive_language(obj, language)
        sdm = obj.session_data_manager
        session = sdm.getSessionData()
        portal = getSite()

        if 'tg' in session.keys() and \
           'old_lang' in session.keys() and \
           not portal.portal_factory.isTemporary(obj):
            IMutableTG(obj).set(session['tg'])
            modified(obj)
            del session['tg']
            old_obj = ITranslationManager(obj)\
                .get_translation(session['old_lang'])
            ILanguageIndependentFieldsManager(old_obj).copy_fields(obj)
            del session['old_lang']
    else:
        set_recursive_language(obj, LANGUAGE_INDEPENDENT)
开发者ID:fredvd,项目名称:plone.app.multilingual,代码行数:37,代码来源:subscriber.py


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