PTS languages
=============

Before we start, we need to set up a manager user to be able to create
the portal:

  >>> uf = self.folder.acl_users
  >>> uf._doAddUser('manager', 'r00t', ['Manager'], [])

We need to 1) configure the Zope 3 i18n message catalogs, 3) register
the PTS languagees adapter and 3) register our test page:

  >>> configure_zcml = """
  ... <configure 
  ...     xmlns="http://namespaces.zope.org/zope"
  ...     xmlns:browser="http://namespaces.zope.org/browser"
  ...     xmlns:i18n="http://namespaces.zope.org/i18n"
  ...     >
  ...   <configure package="Products.Five.tests">
  ...     <i18n:registerTranslations directory="locales" />
  ...   </configure>
  ... 
  ...   <adapter
  ...       for="zope.publisher.interfaces.http.IHTTPRequest"
  ...       provides="zope.i18n.interfaces.IUserPreferredLanguages"
  ...       factory="Products.Five.i18n.PTSLanguages"
  ...       />
  ... 
  ...   <configure package="Products.Five.browser.tests">
  ...     <browser:page
  ...         for="Products.Five.interfaces.IFolder"
  ...         template="pts_test_languages.pt"
  ...         name="pts_test_languages.html"
  ...         permission="zope2.View"
  ...         />
  ...   </configure>
  ... </configure>
  ... """
  >>> from Products.Five import zcml
  >>> zcml.load_string(configure_zcml)

Finally, we need a traversable folder so that the test page we
registered is found:

  >>> from Products.Five.tests.testing import manage_addFiveTraversableFolder
  >>> manage_addFiveTraversableFolder(self.folder, 'ftf')

Now for some actual testing... Our test page is a simple ZPT
translating two messages from different domains.  The first domain is
a Zope 3 style one, the second one comes from PTS.

Both systems should yield the same default language (English) when no
language is specified whatsoever:

  >>> print http(r"""
  ... GET /test_folder_1_/ftf/pts_test_languages.html HTTP/1.1
  ... """)
  HTTP/1.1 200 OK
  ...
  <html>
  <body>
  <!-- fivetest is a Zope 3 style i18n domain, default is a PTS domain -->
  <p>This is a message</p>
  <p>Reload this catalog</p>
  </body>
  </html>

Both systems should honour the HTTP ``Accept-Language`` header in the
same way:

  >>> print http(r"""
  ... GET /test_folder_1_/ftf/pts_test_languages.html HTTP/1.1
  ... Accept-Language: de
  ... """)
  HTTP/1.1 200 OK
  ...
  <html>
  <body>
  <!-- fivetest is a Zope 3 style i18n domain, default is a PTS domain -->
  <p>Dies ist eine Nachricht</p>
  <p>Diesen Katalog neu einlesen</p>
  </body>
  </html>

Both systems should also honour Localizer-specific ways of determining
the language, for example the ``pts_language`` cookie...

  >>> print http(r"""
  ... GET /test_folder_1_/ftf/pts_test_languages.html HTTP/1.1
  ... Accept-Language: de
  ... Cookie: pts_language=en
  ... """)
  HTTP/1.1 200 OK
  ...
  <html>
  <body>
  <!-- fivetest is a Zope 3 style i18n domain, default is a PTS domain -->
  <p>This is a message</p>
  <p>Reload this catalog</p>
  </body>
  </html>

... and the ``language`` form field...

  >>> print http(r"""
  ... GET /test_folder_1_/ftf/pts_test_languages.html?language=en HTTP/1.1
  ... Accept-Language: de
  ... """)
  HTTP/1.1 200 OK
  ...
  <html>
  <body>
  <!-- fivetest is a Zope 3 style i18n domain, default is a PTS domain -->
  <p>This is a message</p>
  <p>Reload this catalog</p>
  </body>
  </html>

... and both the ``pts_language`` cookie and the ``language`` form field:

  >>> print http(r"""
  ... GET /test_folder_1_/ftf/pts_test_languages.html?language=de HTTP/1.1
  ... Accept-Language: en
  ... Cookie: pts_language=fr
  ... """)
  HTTP/1.1 200 OK
  ...
  <html>
  <body>
  <!-- fivetest is a Zope 3 style i18n domain, default is a PTS domain -->
  <p>Dies ist eine Nachricht</p>
  <p>Diesen Katalog neu einlesen</p>
  </body>
  </html>
