Skip to content

Commit

Permalink
Merge pull request #218 from plone/plip13091
Browse files Browse the repository at this point in the history
Plip13091
  • Loading branch information
bloodbare committed Mar 25, 2015
2 parents 5874f0b + 48910d6 commit 2d9023b
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions plone/app/contenttypes/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@
from zope.i18n.interfaces import ITranslationDomain
from zope.i18n.locales import locales
from zope.interface import implements
from plone.registry.interfaces import IRegistry

import pkg_resources

try:
pkg_resources.get_distribution('plone.multilingualbehavior')
except pkg_resources.DistributionNotFound:
HAS_MULTILINGUAL = False
else:
HAS_MULTILINGUAL = True

try:
DEXTERITY_WITH_CONSTRAINS = True
from plone.app.dexterity.behaviors import constrains
Expand Down Expand Up @@ -107,7 +101,8 @@ def addContentToContainer(container, object, checkConstraints=True):


def _get_locales_info(portal):
language = portal.Language()
reg = queryUtility(IRegistry, context=portal)
language = reg['plone.default_language']
parts = (language.split('-') + [None, None])[:3]
locale = locales.getLocale(*parts)

Expand All @@ -118,15 +113,15 @@ def _get_locales_info(portal):
return locale.id.language, False, locale


def _set_language_settings(portal, uses_combined_lanagage):
"""Set the portals language settings from the given lanage codes."""
language = portal.Language()
portal_languages = getToolByName(portal, 'portal_languages')
portal_languages.manage_setLanguageSettings(
language,
[language],
setUseCombinedLanguageCodes=uses_combined_lanagage,
startNeutral=False)
# def _set_language_settings(portal, uses_combined_lanagage):
# """Set the portals language settings from the given lanage codes."""
# language = portal.Language()
# portal_languages = getToolByName(portal, 'portal_languages')
# portal_languages.manage_setLanguageSettings(
# language,
# [language],
# setUseCombinedLanguageCodes=uses_combined_lanagage,
# startNeutral=False)


# ??? Why do we only do this calendar setup when content is created?
Expand Down Expand Up @@ -188,6 +183,7 @@ def create_frontpage(portal, target_language):
content = createContent('Document', id=frontpage_id,
title=title,
description=description,
language=target_language
)
content = addContentToContainer(portal, content)
front_text = None
Expand Down Expand Up @@ -228,7 +224,8 @@ def create_news_topic(portal, target_language):
u'Site News')
container = createContent('Folder', id=news_id,
title=title,
description=description)
description=description,
language=target_language)
container = addContentToContainer(portal, container)
_createObjectByType('Collection', container,
id='aggregator', title=title,
Expand Down Expand Up @@ -272,7 +269,8 @@ def create_events_topic(portal, target_language):
u'Site Events')
container = createContent('Folder', id=events_id,
title=title,
description=description)
description=description,
language=target_language)
container = addContentToContainer(portal, container)
_createObjectByType('Collection', container,
id='aggregator', title=title,
Expand Down Expand Up @@ -319,7 +317,8 @@ def configure_members_folder(portal, target_language):
u"Site Users")
container = createContent('Folder', id=members_id,
title=title,
description=description)
description=description,
language=target_language)
container = addContentToContainer(portal, container)
container.setOrdering('unordered')
container.reindexObject()
Expand Down Expand Up @@ -350,7 +349,7 @@ def step_import_content(context):
target_language, is_combined_language, locale = _get_locales_info(portal)

# Set up Language specific information
_set_language_settings(portal, is_combined_language)
# _set_language_settings(portal, is_combined_language)
_setup_calendar(locale)
_setup_visible_ids(target_language, locale)
_delete_at_example_content(portal)
Expand Down Expand Up @@ -399,19 +398,19 @@ def step_setup_various(context):
if context.readDataFile('plone.app.contenttypes_default.txt') is None:
return
portal = context.getSite()
enable_multilingual_behavior(portal)


def enable_multilingual_behavior(portal):
if not HAS_MULTILINGUAL:
return
types_tool = portal.portal_types
all_ftis = types_tool.listTypeInfo()
dx_ftis = [x for x in all_ftis if getattr(x, 'behaviors', False)]
for fti in dx_ftis:
behaviors = [i for i in fti.behaviors]
behaviors.extend([
'plone.multilingualbehavior.interfaces.IDexterityTranslatable',
])
behaviors = tuple(set(behaviors))
fti._updateProperty('behaviors', behaviors)
# enable_multilingual_behavior(portal)


# def enable_multilingual_behavior(portal):
# if not HAS_MULTILINGUAL:
# return
# types_tool = portal.portal_types
# all_ftis = types_tool.listTypeInfo()
# dx_ftis = [x for x in all_ftis if getattr(x, 'behaviors', False)]
# for fti in dx_ftis:
# behaviors = [i for i in fti.behaviors]
# behaviors.extend([
# 'plone.app.multilingual.dx.interfaces.IDexterityTranslatable',
# ])
# behaviors = tuple(set(behaviors))
# fti._updateProperty('behaviors', behaviors)

0 comments on commit 2d9023b

Please sign in to comment.