Opened 7 years ago

Closed 7 years ago

#15774 closed Bug (duplicate)

UnicodeDecodeError with makemessages

Reported by: Dirk Eschler Owned by: nobody
Component: Internationalization Version: 1.3
Severity: Normal Keywords:
Cc: eschler@…, james@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:


Running makemessages in the project folder throws a UnicodeDecodeError here with django-1.3. Everything works fine with django-1.2.

$ ./ makemessages -l de
processing language de
Traceback (most recent call last):
  File "./", line 11, in <module>
  File "/path/to/django/core/management/", line 438, in execute_manager
  File "/path/to/django/core/management/", line 379, in execute
  File "/path/to/django/core/management/", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/path/to/django/core/management/", line 220, in execute
    output = self.handle(*args, **options)
  File "/path/to/django/core/management/", line 351, in handle
    return self.handle_noargs(**options)
  File "/path/to/django/core/management/commands/", line 365, in handle_noargs
    make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete)
  File "/path/to/django/core/management/commands/", line 233, in make_messages
    f.write(templatize(src, orig_file[2:]))
  File "/path/to/django/utils/translation/", line 127, in templatize
    return _trans.templatize(src, origin)
  File "/path/to/django/utils/translation/", line 450, in templatize
    content = u''.join(comment)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 284: ordinal not in range(128)

Is this in any way related to the changes made in project level translation handling mentioned in the 1.3 release notes? I'm not sure if i understand them correctly, does it mean that project level should be avoided in favour of app level translations in general? Adding the project locale folder to LOCALE_PATHS doesn't make a difference by the way, same UnicodeDecodeError.

Change History (4)

comment:1 Changed 7 years ago by James Aylett

I've had this too; it should (?) only happen with non-ASCII characters in templates. The problem is that higher up the call stack ( src is a str (it's read straight out of a file), so that:

    content = u''.join(comment)

doesn't work, because the members of comment are actually str not unicode. Changing django/utils/translation/ to the following fixes it for me:

    content = u''.join([l.decode('utf-8') for l in comment])

An actual fix is going to be a bit more subtle than that…

comment:2 Changed 7 years ago by James Aylett

Cc: james@… added

comment:3 Changed 7 years ago by anonymous

Just ran into the same problem. I relocated the locale folder to my main application instead of my project root but still got the same error.

I managed to pin point the offending code by removing all the templates from the template folder and then put them back one by one while doing a makemessage -a between each of them.

It turned out that the error was triggered by a single file, which didn't seem to contain non-ascii character in any trans block.. So I did the same for the code, I removed it all and started to put it back chunk by chunk while doing a makemessages -a between each chunks.

Which led me to find out that the offending non-ascii character was in a TEMPLATE COMMENT.

IMO the translation module should ignore anything that isn't in a trans/blocktrans altogether. In my case we are French, so often in template we've put French comments. I'll probably have a lots of projects that will start to break the translation module because of this this..

comment:4 Changed 7 years ago by Jonas H.

Easy pickings: unset
Resolution: duplicate
Status: newclosed

Duplicate of #15848

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