本文整理汇总了Python中plone.app.multilingual.interfaces.ITranslationManager.add_translation方法的典型用法代码示例。如果您正苦于以下问题:Python ITranslationManager.add_translation方法的具体用法?Python ITranslationManager.add_translation怎么用?Python ITranslationManager.add_translation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.app.multilingual.interfaces.ITranslationManager
的用法示例。
在下文中一共展示了ITranslationManager.add_translation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_translation
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import add_translation [as 别名]
def create_translation(self, *args, **kwargs):
"""Create translation for an object with uid in the given
target_language and return its UID
Usage::
Create translation /plone/en/foo ca title=Translated
"""
disableCSRFProtection()
# Parse arguments:
uid_or_path = args[0]
target_language = args[1]
# BBB: Support keywords arguments with robotframework < 2.8.3
kwargs.update(dict([arg.split('=', 1) for arg in args[2:]]))
# Look up translatable content
pc = getToolByName(self, "portal_catalog")
uid_results = pc.unrestrictedSearchResults(UID=uid_or_path)
path_results = pc.unrestrictedSearchResults(
path={'query': uid_or_path.rstrip('/'), 'depth': 0})
obj = (uid_results or path_results)[0]._unrestrictedGetObject()
# Translate
manager = ITranslationManager(obj)
manager.add_translation(target_language)
translation = manager.get_translation(target_language)
# Update fields
data = constructMessageFromSchemata(obj, iterSchemata(obj))
for key, value in kwargs.items():
del data[key]
data[key] = Header(value, 'utf-8')
del data['language']
initializeObjectFromSchemata(translation, iterSchemata(obj), data)
notify(ObjectModifiedEvent(translation))
# Return uid for the translation
return IUUID(translation)
示例2: translate
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import add_translation [as 别名]
def translate(content, target_language='en'):
manager = ITranslationManager(content)
manager.add_translation(target_language)
return manager.get_translation(target_language)
示例3: __call__
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import add_translation [as 别名]
def __call__(self):
context = self.context
request = self.request
catalog = context.portal_catalog
portal = api.portal.get()
alsoProvides(request, IDisableCSRFProtection)
root_zh = portal.get('zh')
if not root_zh: return
root_en = portal.get('en')
if not root_en: return
prog_zh = root_zh.get('programs')
if not prog_zh: return
prog_en = root_en.get('programs')
if not prog_en: return
container_zh = prog_zh.get('recipients')
if not container_zh: return
container_en = prog_en.get('recipients')
if not container_en: return
with open('grant-list.csv', "rb") as file:
rows = csv.reader(file, delimiter='\t')
next(rows, None)
for row in rows:
folder_zh = container_zh.get(str(row[1]))
if not folder_zh:
fldr = api.content.create(
type='Folder',
container=container_zh,
id=row[1],
title=row[1]
)
fldr.reindexObject()
if row[2] == '': row[2] = row[3]
if row[4] == '': row[4] = row[5]
if row[3] == '': row[3] = row[2]
if row[5] == '': row[5] = row[4]
ctnt = api.content.create(
type='Grant',
container=container_zh.get(str(row[1])),
id=row[0],
title=safe_unicode(row[2]),
year=row[1],
director=row[4],
description=row[6],
department=row[7],
region=row[8],
category=row[9],
budget=row[10],
currency=row[11],
status=row[12]
)
manager = ITranslationManager(ctnt)
manager.add_translation('en')
trns = manager.get_translation('en')
trns.id = str(row[0])
trns.title = row[3]
trns.year = row[1]
trns.director = row[5]
trns.description = row[6]
trns.department = row[7]
trns.region = row[8]
trns.category = row[9]
trns.budget = row[10]
trns.currency = row[11]
trns.status = row[13]
ctnt.reindexObject()
trns.reindexObject()
示例4: makeTranslation
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import add_translation [as 别名]
def makeTranslation(content, language="en"):
manager = ITranslationManager(content)
manager.add_translation(language)
return manager.get_translation(language)
示例5: makeTranslation
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import add_translation [as 别名]
def makeTranslation(content, language='en'):
manager = ITranslationManager(content)
manager.add_translation(language)
import transaction; transaction.commit()
return manager.get_translation(language)