Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 13 and Version 14 of Internationalization


Ignore:
Timestamp:
02/06/06 16:20:33 (13 years ago)
Author:
oavtal@…
Comment:

Added unicode request handling tip

Legend:

Unmodified
Added
Removed
Modified
  • Internationalization

    v13 v14  
    111111 
    112112The _() and all formatting functions return unicode strings. 
     113 
     114= Receiving international (UTF-8) form data = 
     115 
     116The first thing to do is to add a tag similar to the following at the head of your template: 
     117 
     118{{{<meta content="text/html; charset=UTF-8" http-equiv="content-type" />}}} 
     119 
     120It will let the browser know it operates in "unicode mode". 
     121 
     122When the browser sends unicode data in a request (via a textarea, for example), CherryPy gives you the string as is. 
     123you need to convert it to unicode yourself: 
     124{{{ 
     125#!python 
     126@turbogears.expose(template="myproject.templates.welcome") 
     127def test(self, text): 
     128    text = text.encode("utf-8") 
     129    # ... The rest of the code 
     130}}} 
     131 
     132Another, easier way, is to use a CherryPy filter. A filter is a function that runs on the input/output automatically. CherryPy has several built-ins. One of them is {{{decoding_filter}}}, that decodes all of the incoming request parameters using a given encoding. 
     133 
     134In your project's config.py, add this: 
     135{{{ 
     136#!python 
     137path("/") 
     138decoding_filter.on =  True 
     139decoding_filter.encoding = "utf-8" 
     140}}}