Login

Snippets by angerman

Snippet List

gettext parachut for python 2.3 with unicode and utf-8

I ran into this because my development system is django on python 2.4 and I deploy to 2.3. It's a corner case where you use gettext, the \# -\*- coding: utf-8 -\*- header and want to have a consistant style in your file. It is encouraged to use the unicode marker like u'string', but this does not work for __str__ methods of your models as they are called by the ``str'' function and that function again can not handle unicode. It would be really nice to have all unicode intern and only do the appropriated encoding on the output. Anyway. With this little helper you can clutter your files with _('stirng of heart with € äüöß') ... With the coding directive in the header python 2.4 and gettext can handle this on 2.3 though they can't. So this script adds a parachut to the gettext wrapper that kicks in if gettext is failing.

  • unicode
  • gettext
  • utf-8
  • 2.4
  • 2.3
Read More

angerman has posted 1 snippet.