本文整理汇总了Python中plone.app.multilingual.interfaces.ITranslationManager.query_canonical方法的典型用法代码示例。如果您正苦于以下问题:Python ITranslationManager.query_canonical方法的具体用法?Python ITranslationManager.query_canonical怎么用?Python ITranslationManager.query_canonical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.app.multilingual.interfaces.ITranslationManager
的用法示例。
在下文中一共展示了ITranslationManager.query_canonical方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_alternate_languages
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import query_canonical [as 别名]
def get_alternate_languages(self):
"""Cache relative urls only. If we have multilingual sites
and multi domain site caching absolute urls will result in
very inefficient caching. Build absolute url in template.
"""
tm = ITranslationManager(self.context)
catalog = getToolByName(self.context, 'portal_catalog')
results = catalog(TranslationGroup=tm.query_canonical())
alternates = []
for item in results:
url = item.getURL()
alternates.append({
'lang': item.Language,
'url': url,
})
return alternates
示例2: get_alternate_languages
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import query_canonical [as 别名]
def get_alternate_languages(self):
"""Cache relative urls only. If we have multilingual sites
and multi domain site caching absolute urls will result in
very inefficient caching. Build absolute url in template.
"""
tm = ITranslationManager(self.context)
catalog = getToolByName(self.context, 'portal_catalog')
results = catalog(TranslationGroup=tm.query_canonical())
plone_site = getUtility(IPloneSiteRoot)
portal_path = '/'.join(plone_site.getPhysicalPath())
portal_path_len = len(portal_path)
alternates = []
for item in results:
path_len = portal_path_len + len('{0:s}/'.format(item.Language))
url = item.getURL(relative=1)[path_len:]
alternates.append({
'lang': item.Language,
'url': url.strip('/'),
})
return alternates