[Zope3-Users] utf-8/latin-1 content in page templates

Andreas Reuleaux reuleaux at web.de
Wed Jun 15 12:26:33 EDT 2005


I would like to use utf-8 (latin-1) content in page templates like
this

  <p>Hier hätte ich gerne Umlaute etc.: Österreich, daß...</p>

("here I would like to have umlauts etc.")  I. e. I would like to have
default strings with German umlauts. - I was surprised this was not
possible in the first place

  'ascii' codec can't decode byte ... in position ...: ordinal not in range(128)

I tried several workarounds - none of them I liked very much:

* Using i18n I could successfully write

    <p i18n:translate="">hier-haette-ich</p>

  and define the German message strings in a .po file. - Actually this
  is starting with an English (ascii-only) default string
  ("hier-haette-ich") and than defining a German translation. - I
  wonder why it should not be possible the other way around (start
  with German default strings and later define the English
  translations). - Imagine a small German only site: Every string with
  umlauts has to go to the .po file: Quite some overhead.

* The p tag was successfully rendered when I used 

    <?xml version="1.0" encoding="utf-8"?>
  
  in the first line of the template (respectively
  encoding="iso-8859-1"). I don't like this approach for several
  reasons: The main reason is that IE will then interpret the page in
  quirks mode (instead of standards mode) - see e. g. Jeffry Zeldmans
  book "designing with web standards".

* I came up with a solution which obviously is not very elegant:
  
    <p tal:content="python: u'Hier hätte ich gerne ...'" />

  but it works for me if the string is in latin-1

What I would really like is the possibility of specifying the encoding when
registering the page:

  <browser:page
      name="mypage.html"
      template="mypage.pt"
      encoding="utf-8"
      ...
  />

I have not tried yet to render the page from a view class (how would I do that?)

Am I missing something?

Thanks in advance,
  Andreas


More information about the Zope3-users mailing list