#8343 closed (worksforme)
Using umlauts with blocktrans results in TemplateSyntaxError
Reported by: | Oliver Weichhold | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Keywords: | localization | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
/project/app/locale/de/django.po:
msgid "foomsg %(val)s %(val)s"
msgstr "Föö bar %(val)s foo %(val2)s%
/project/app/templates/foo.html:
{% blocktrans with c.foo as val and c.bar as val2 %}foomsg {{ val }}{{ val2 }}{% endblocktrans %}
Result:
Page is not rendered but a TemplateSyntaxError is thrown: Caught an exception while rendering: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)
Change History (5)
comment:1 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
I was sure but to be 100% on the safe side I loaded the .po into Notepad++, did Format -> Convert to UTF8, followed by Format -> Encode in UTF8 without BOM and save. The file didn't change though.
comment:3 by , 16 years ago
Also check your template encoding.
But since this is not a forum, further discussions on #django, #django-de or the django list.
comment:4 by , 16 years ago
milestone: | 1.0 beta |
---|
This works fine for me, too (lots of internal translations use non-ASCII characters in the msgstr
values). Asking on django-users with some details of how to repeat the problem might yield somebody who can spot what you're doing that's causing the problem.
comment:5 by , 16 years ago
Further research reveiled that when in django/templatetags/i18n.py:82 BlockTranslateNode.render() calls translation.ugettext(). The returned object is a str rather than a unicode or a SafeString.
Adding:
result = force_unicode(result)
prevents the crash but is not clear to me how ugettext can return non unicode results in the first place.
Are you shure your django.po has UTF-8 encoding?