Current

This document is valid for the current version of Plone.

Language negotiation

by Plone Documentation Team last modified Dec 12, 2009 10:33 PM
Contributors: Mikko Ohtamma, Martin Aspeli, Kamon Ayeva, Israel Saeta Pérez
How the current language of the viewed page is defined

Each page view has a language associated with which is negotiated based on various factors. Negotiation is handled by PlacelessTranslationService and plone.i18n modules.

Several factors determine what is the current language:

  • Cookies (user chosen setting from the language selector)
  • Domain name: Top level domain name (TLD) like plone.fi for Finnish, plone.se for Swedish or subdomain name like fi.plone.org for Finnish.
  • The language of the context: what function context.Language() returns. The user can set this on content metadata edit page.
  • Language headers send by the web browser

Language is negotiated at the beginning of the page view.

Getting the current language

How to get the active language for the current context and HTTP request

from Acquisition import aq_inner
from zope.component import getMultiAdapter

context = aq_inner(self.context)
portal_state = getMultiAdapter((context, self.request), name=u'plone_portal_state')

current_language = portal_state.language()