3

Plone 3.3.5, LinguaPlone and Products.CacheSetup installed.

Language cookie set for portal_css and portal_javascript files

      HTTP/1.1 200 OK
      Server: Zope/(unreleased version, python 2.4.5, linux2) ZServer/1.1 Plone/3.3.5
      Expires: Tue, 26 Apr 2011 10:42:56 GMT
      Last-Modified: Tue, 19 Apr 2011 10:42:56 GMT
      Cache-Control: max-age=604800
      Content-Type: application/x-javascript;charset=utf-8
      Set-Cookie: I18N_LANGUAGE="en"; Path=/
      Content-Length: 192404
      Date: Tue, 19 Apr 2011 10:42:56 GMT
      X-Varnish: 452768899
      Age: 0
      Via: 1.1 varnish
      Connection: keep-alive
    Pituus: 192404 (188K) [application/x-javascript]
    Tallennetaan kohteeseen ”tiny_mce-cachekey1974.js”

This prevents caching. I found some old information related to this:

http://www.evax.fr/papers/nginx-varnish-and-multilingual-plone

1) Why it is set? I assume all resources are language neutral by default and only in special conditions contain language specific stuff.

2) How do I get rid off it? Maybe there is a smarter way than monkey-patching, but not documented anywhere.

3) Any changes related to this in Plone 4.x?

1 Answer 1

3

The cookie is set by the LanguageTool, and is only set when not present yet in the request, or different from what was set in the request.

The LanguageTool normally would only look at that very cookie for deciding what language to use. In normal Plone use therefor, you will never see that Set-Cookie header on CSS and JS resources. LinguaPlone however, configures the LanguageTool to look at a lot more information, including the URL you were trying to access, to determine a language to use for the response.

With LinguaPlone installed, what the LanguageTool does is to determine the correct language for every resource accessed, as that is the only way to ensure a consistent UI language through-out.

The cookie is normally already set on load of the main page (which subsequently loads JS and CSS with the cookie set). Thus, in the normal scenario your CSS and JS are perfectly cacheable. You are only seeing the Set-Cookie header because there is no corresponding Cookie: I18N_LANGUAGE="en" header in the request.

If you have to control this for your specific use-cases, you could monkeypatch Products.PloneLanguageTool.LanguageTool.LanguageTool.__call__, which is a before-publishing-traverse hook that will trigger the language determination on every request. I'd recommend using collective.monkeypatcher for this. Here is what I did in a recent project where the site was migrated with a mixed set of languages throughout the tree (something we'll have to untangle at some point in the future):

configure.zcml:

<?xml version="1.0"?>
<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:monkey="http://namespaces.plone.org/monkey"
    >
<!-- other directives -->

<include package="collective.monkeypatcher" />
<monkey:patch
    description="Patch LanguageTool before traverse hook to prevent setting
                 the language cookie"
    class="Products.PloneLanguageTool.LanguageTool.LanguageTool"
    original="__call__"
    replacement=".patches.LanguageTool__call__"
    preserveOriginal="true"
    />
</configure>

and in the patches.py module:

from ZPublisher.HTTPRequest import HTTPRequest

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']

Note that the patch deletes the cookie after the fact, unless set_language was used on the current request.

There are no changes pending for this behaviour for Plone 4.x.

1

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.