Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#8343 closed (worksforme)

Using umlauts with blocktrans results in TemplateSyntaxError

Reported by: oliverw Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords: localization
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



msgid "foomsg %(val)s %(val)s"
msgstr "Föö bar %(val)s foo %(val2)s%

{% blocktrans with as val and as val2 %}foomsg {{ val }}{{ val2 }}{% endblocktrans %}


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 Changed 8 years ago by toke

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

Are you shure your django.po has UTF-8 encoding?

comment:2 Changed 8 years ago by oliverw

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 Changed 8 years ago by toke

Also check your template encoding.
But since this is not a forum, further discussions on #django, #django-de or the django list.

comment:4 Changed 8 years ago by mtredinnick

  • milestone 1.0 beta deleted

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 Changed 8 years ago by oliverw

Further research reveiled that when in django/templatetags/ BlockTranslateNode.render() calls translation.ugettext(). The returned object is a str rather than a unicode or a SafeString.


result = force_unicode(result)

prevents the crash but is not clear to me how ugettext can return non unicode results in the first place.

Note: See TracTickets for help on using tickets.
Back to Top