carlxaeron / django-rosetta

Automatically exported from code.google.com/p/django-rosetta
MIT License
0 stars 0 forks source link

very bad str to unicode conversion #63

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
User will have an unicode character in its first- or last-name.
Trying to save translation will raise an error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u0142' in position 
5: ordinal not in 
range(128)

this is because of line 269 in "rosetta/views.py":
rosetta_i18n_pofile.metadata['Last-Translator'] = str(u"%s %s <%s>" 
%(request.user.first_name,request.user.last_name,req
uest.user.email))

which should be at least (if you want ascii characters only):
rosetta_i18n_pofile.metadata['Last-Translator'] = (u"%s %s <%s>" 
%(request.user.first_name,request.user.last_name,req
uest.user.email)).encode('ascii', 'ignore')

or if you want to avoid questionmarks and find closest ascii character 
replacement:
import unicodedata
unicodedata.normalize('NFKD', u"%s %s <%s>" 
%(request.user.first_name,request.user.last_name,request.user.email)).encode('as
cii', 'ignore')

Original issue reported on code.google.com by janusz.harkot@gmail.com on 12 Nov 2009 at 1:32

GoogleCodeExporter commented 8 years ago
title shoud state "unicede to str"

Original comment by janusz.harkot@gmail.com on 12 Nov 2009 at 1:33

GoogleCodeExporter commented 8 years ago
Thank you so much for the code bits, I wasn't aware of unicodedata.normalize. 
Applied in r81.

Original comment by mbonetti on 12 Nov 2009 at 2:25