diff --git a/plone/app/dexterity/behaviors/metadata.py b/plone/app/dexterity/behaviors/metadata.py index 13df017b..c1166128 100644 --- a/plone/app/dexterity/behaviors/metadata.py +++ b/plone/app/dexterity/behaviors/metadata.py @@ -39,24 +39,30 @@ def default_language(context): # If we are adding a new object, context will be the folderish object where # this new content is being added + # import pdb; pdb.set_trace() language = None - if context is not None and not IPloneSiteRoot.providedBy(context): - language = context.Language() - if not language: + # Try to get the language from context or parent(s) + while context is not None and not IPloneSiteRoot.providedBy(context): + try: + # Use aq_base so the .language attribute isn't acquired from root + language = context.aq_base.Language() + except AttributeError: # Accesses .language # If we are here, it means we were editing an object that didn't # have its language set or that the container where we were adding # the new content didn't have a language set. So we check its - # parent, unless we are at site's root, in which case we get site's - # default language - if not IPloneSiteRoot.providedBy(context.aq_parent): - language = context.aq_parent.Language() + # parent. + context = context.__parent__ + + pl = getToolByName(getSite(), 'portal_languages') + default_language = pl.getDefaultLanguage() if not language: - # Finally, if we still don't have a language, then just use site's - # default - pl = getToolByName(getSite(), 'portal_languages') - language = pl.getDefaultLanguage() + language = default_language + + # Is the language supported/enabled at all? + if language not in pl.getAvailableLanguages(): + language = default_language return language