本文整理汇总了Python中plone.app.multilingual.interfaces.ITranslationManager.register_translation方法的典型用法代码示例。如果您正苦于以下问题:Python ITranslationManager.register_translation方法的具体用法?Python ITranslationManager.register_translation怎么用?Python ITranslationManager.register_translation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.app.multilingual.interfaces.ITranslationManager
的用法示例。
在下文中一共展示了ITranslationManager.register_translation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import register_translation [as 别名]
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()
示例2: link_translations
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import register_translation [as 别名]
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)
示例3: _update_deferred
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import register_translation [as 别名]
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())
示例4: linkTranslations
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import register_translation [as 别名]
def linkTranslations(self):
"""Links the translations of the default language Folders
"""
doneSomething = False
try:
canonical = ITranslationManager(self.folders[self.defaultLanguage])
except TypeError as e:
raise TypeError(str(e) + u' Are your folders ITranslatable?')
for language in self.languages:
if language == self.defaultLanguage:
continue
if not canonical.has_translation(language):
language_folder = self.folders[language]
canonical.register_translation(language, language_folder)
doneSomething = True
if doneSomething:
logger.info(u'Translations linked.')
return doneSomething
示例5: __iter__
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import register_translation [as 别名]
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()
示例6: update
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import register_translation [as 别名]
def update(self, obj, data):
ILanguage(obj).set_language(data['language'])
IMutableTG(obj).set(data['translation_group_uuid'])
manager = ITranslationManager(obj)
manager.register_translation(data['language'], obj)