Internationalization and cache

Description

Using Plone translation facilities in the presence of caching.

Introduction

You need to have the following monkey-patch in place if you intend to use LinguaPlone (translated content) with front-end caching servers. Otherwise CSS, JS and media files will have a language cookie set on them, preventing cache from working.

Note

This is a well-known Plone issue.

Example:

from ZPublisher.HTTPRequest import HTTPRequest

LanguageTool._old___call__ = LanguageTool.__call__

def LanguageTool__call__(self, container, req):
    """The __before_publishing_traverse__ hook.

    Patched to *not* set the language cookie, as this breaks the site model.

    """
    self._old___call__(container, req)
    if not isinstance(req, HTTPRequest):
        return None
    response = req.response
    if 'I18N_LANGUAGE' in response.cookies:
        if 'set_language' in req.form:
            return None
        del response.cookies['I18N_LANGUAGE']

LanguageTool.__call__ = LanguageTool__call__

More info

Table Of Contents

About Plone

This is documentation for Plone®. Plone is a popular, open source, content management system written in Python programming language.




Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Go to Internationalization and cache on GitHub.
  2. Press Fork and edit this file button.
  3. Edit file contents using GitHub's text editor in your web browserm
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on Github.

For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.