本文整理汇总了Python中plone.app.multilingual.interfaces.ITranslationManager.get_translations方法的典型用法代码示例。如果您正苦于以下问题:Python ITranslationManager.get_translations方法的具体用法?Python ITranslationManager.get_translations怎么用?Python ITranslationManager.get_translations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.app.multilingual.interfaces.ITranslationManager
的用法示例。
在下文中一共展示了ITranslationManager.get_translations方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import get_translations [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: test_content_is_linked
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import get_translations [as 别名]
def test_content_is_linked(self):
items = self._run_transmogrifier()
self.assertEqual(4, len(items))
manager = ITranslationManager(self.folder_en)
self.assertEqual(self.folder_de, manager.get_translation('de'),
'English and German content should be linked.')
self.assertEqual(2, len(manager.get_translations()))
manager = ITranslationManager(self.file_de)
self.assertEqual(self.file_en, manager.get_translation('en'),
'English and German content should be linked.')
self.assertEqual(2, len(manager.get_translations()))
示例3: get_all_translations
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import get_translations [as 别名]
def get_all_translations(self, content):
"""Return all translations excluding the just modified content"""
translations_list_to_process = []
content_lang = queryAdapter(content, ILanguage).get_language()
canonical = ITranslationManager(content)
translations = canonical.get_translations()
for language in translations.keys():
if language != content_lang:
translations_list_to_process.append(translations[language])
return translations_list_to_process
示例4: test_move_content_existing_translation_inside
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import get_translations [as 别名]
def test_move_content_existing_translation_inside(self):
f_ca = createContentInContainer(
self.portal['ca'], 'Folder', title=u"Test folder")
a_ca = createContentInContainer(
self.portal['ca']['test-folder'],
'Document', title=u"Test document")
a_en = api.translate(a_ca, 'en')
translations = ITranslationManager(self.portal['en'][a_en.id])
self.assertEqual(translations.get_translations(),
{'ca': self.portal['ca'][f_ca.id][a_ca.id],
'en': self.portal['en'][a_ca.id]})
self.assertIn(a_en.id, self.portal['en'].objectIds())
self.assertEqual(a_en, self.portal['en'][a_en.id])
# Change the content language of the created folder to 'en'
multilingualMoveObject(f_ca, 'en')
self.assertIn(f_ca.id, self.portal['en'].objectIds())
self.assertEqual(f_ca, self.portal['en'][f_ca.id])
self.assertIn(a_ca.id, self.portal['en'][f_ca.id].objectIds())
self.assertEqual(a_ca, self.portal['en'][f_ca.id][a_ca.id])
adapter = ILanguage(self.portal['en'][f_ca.id])
self.assertEqual(adapter.get_language(), 'en')
adapter = ILanguage(self.portal['en'][f_ca.id][a_ca.id])
self.assertEqual(adapter.get_language(), 'en')
translations = ITranslationManager(self.portal['en'][f_ca.id][a_ca.id])
self.assertEqual(translations.get_translations(),
{'en': self.portal['en'][f_ca.id][a_ca.id]})
translations = ITranslationManager(self.portal['en'][a_en.id])
self.assertEqual(translations.get_translations(),
{'en': self.portal['en'][a_en.id]})
示例5: BabelUtils
# 需要导入模块: from plone.app.multilingual.interfaces import ITranslationManager [as 别名]
# 或者: from plone.app.multilingual.interfaces.ITranslationManager import get_translations [as 别名]
class BabelUtils(BrowserView):
def __init__(self, context, request):
super(BabelUtils, self).__init__(context, request)
portal_state = getMultiAdapter((context, request),
name="plone_portal_state")
self.portal_url = portal_state.portal_url()
# If there is any translation_info lets use it
try:
self.group = TranslationManager(request.translation_info['tg'])
except AttributeError:
self.group = ITranslationManager(self.context)
def getGroup(self):
return self.group
def getTranslatedLanguages(self):
return self.group.get_translated_languages()
def getPortal(self):
portal_url = getToolByName(self.context, 'portal_url')
return portal_url
def objToTranslate(self):
return self.context
def gtenabled(self):
registry = getUtility(IRegistry)
settings = registry.forInterface(IMultiLanguageExtraOptionsSchema,
prefix="plone")
key = settings.google_translation_key
return key is not None and len(key.strip()) > 0
def languages(self):
""" Deprecated """
context = aq_inner(self.context)
ls = LanguageSelector(context, self.request, None, None)
ls.update()
results = ls.languages()
supported_langs = [v['code'] for v in results]
missing = set([str(c) for c in supported_langs])
lsv = LanguageSelectorViewlet(context, self.request, None, None)
translations = lsv._translations(missing)
# We want to see the babel_view
append_path = ('', 'babel_view',)
non_viewable = set()
for data in results:
code = str(data['code'])
data['translated'] = code in translations.keys()
appendtourl = '/'.join(append_path)
if data['translated']:
trans, direct, has_view_permission = translations[code]
if not has_view_permission:
# shortcut if the user cannot see the item
non_viewable.add((data['code']))
continue
data['url'] = trans.absolute_url() + appendtourl
else:
non_viewable.add((data['code']))
# filter out non-viewable items
results = [r for r in results if r['code'] not in non_viewable]
return results
def translated_languages(self):
context = aq_inner(self.context)
tool = getToolByName(context, 'portal_languages', None)
checkPermission = getSecurityManager().checkPermission
translations = self.group.get_translations()
translated_info =\
[dict(code=key,
info=tool.getAvailableLanguageInformation()[key],
obj=translations[key]) for key in translations]
default_language = tool.getDefaultLanguage()
translated_shown = []
for lang_info in translated_info:
# Mark the default language as the first translation shown
if lang_info['code'] == default_language:
lang_info['isDefault'] = True
else:
lang_info['isDefault'] = False
# Remove the translation of the content currently being
# translated In case it's temporal we show as language is not
# already set on AT
portal_factory = getToolByName(
self.context,
'portal_factory',
None
)
#.........这里部分代码省略.........