Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 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:

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)

Attachments (0)

Change History (5)

comment:1 Changed 6 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 6 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 6 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 6 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 6 years ago by oliverw

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.