本文整理汇总了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
示例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'
示例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)
示例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
示例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)
示例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())
示例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)
示例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)
示例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)
示例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
示例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)
示例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
示例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)
示例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()
示例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)