• Members 19 posts
    June 2, 2014, 7:10 p.m.

    I'm trying to translate the messages in app/register/forms.py to chinese which needs utf8.
    e.g
    row11:username = forms.CharField(label=_('用户名')
    row44:"你的用户名. %(min)s 到 %(max)s 个文字、字母或数字.") % help_text_formats

    I've add #-- coding:utf-8 -- on the first row of forms.py.
    but turn out django/Misago still use ascii and give me an error.

    Have I missed something?


    traceback information:
    Traceback:
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/django/core/handlers/base.py" in get_response
    114. response = wrapped_callback(request, callback_args, callback_kwargs)
    File "/Users/lizaoji/Program/svn/xtdlx/1/misago/decorators.py" in decorator
    43. return f(*args,
    kwargs)
    File "/Users/lizaoji/Program/svn/xtdlx/1/misago/decorators.py" in decorator
    31. return f(
    args, kwargs)
    File "/Users/lizaoji/Program/svn/xtdlx/1/misago/decorators.py" in decorator
    21. return f(*args,
    kwargs)
    File "/Users/lizaoji/Program/svn/xtdlx/1/misago/decorators.py" in decorator
    64. return f(*args, kwargs)
    File "/Users/lizaoji/Program/svn/xtdlx/1/misago/apps/register/views.py" in form
    85. context_instance=RequestContext(request));
    File "/Users/lizaoji/Program/svn/xtdlx/1/misago/shortcuts.py" in render_to_response
    16. return django_render_to_response(template_name, dictionary, content_type=kwargs.get('content_type'))
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/django/shortcuts/init.py" in render_to_response
    29. return HttpResponse(loader.render_to_string(*args,
    kwargs), httpresponse_kwargs)
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/django/template/loader.py" in render_to_string
    164. return t.render(Context(dictionary))
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/django_jinja/base.py" in render
    131. return super(Template, self).render(new_context)
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/jinja2/environment.py" in render
    969. return self.environment.handle_exception(exc_info, True)
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/jinja2/environment.py" in handle_exception
    742. reraise(exc_type, exc_value, tb)
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../templates/cranefly/register.html" in top-level template code
    80. {% trans %}������������{% endtrans %}
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../templates/cranefly/layout.html" in top-level template code
    2. {% from "cranefly/macros.html" import messages_list %}
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../templates/cranefly/base.html" in top-level template code
    19. {% block body %}{% endblock %}
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../templates/cranefly/layout.html" in block "body"
    154. {% block container %}
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../templates/cranefly/layout.html" in block "container"
    158. {% block content %}
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../templates/cranefly/register.html" in block "content"
    26. {{ form_theme.row(form.username, attrs={'class': 'span8'}) }}
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../templates/forms.html" in template
    12. <label class="control-label" for="id_{{ _field.html_name }}">{% if label %}{{ label }}{% elif _field.label %}{{ _field.label }}{% else %}{{ _field.html_name }}{% endif %}:</label>
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/django/utils/functional.py" in wrapper
    125. res = func(*self.__args,
    self.kw)
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/django/utils/translation/
    init__.py" in ugettext
    76. return _trans.ugettext(message)
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/django/utils/translation/trans_real.py" in ugettext
    281. return do_translate(message, 'ugettext')
    File "/Users/lizaoji/Program/svn/xtdlx/1/deployment/../site-packages/django/utils/translation/trans_real.py" in do_translate
    264. result = getattr(_default, translation_function)(eol_message)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py" in ugettext
    404. return unicode(message)

    Exception Type: UnicodeDecodeError at /register/
    Exception Value: 'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)

  • June 2, 2014, 7:28 p.m.

    At top of the file put following comment:

    #-*- coding: utf-8 -*-

    Now prepend all strings with chinese chars in file with "u", so '用户名' becomes u'用户名'. This will make Python handle strings as unicodes, not ASCII

  • Members 19 posts
    June 2, 2014, 7:56 p.m.

    Oh,sorry for the silly question。
    My poor knowledge of python - -|||