ioeric ioeric - 5 months ago 14x
Python Question

How to change Django's default label name of comment form into Chinese?

I am using Django's built-in comments app. But I have met one problem.

The default label for the comments form is English(e.g. "Name","Email Address"), but I'd like to change them into Chinese. So I went to

and amend them as below:

name = forms.CharField(label=_("姓名 Name"), max_length=50)
email = forms.EmailField(label=_("邮箱 Email"))
url = forms.URLField(label=_("网站 URL"), required=False)
comment = forms.CharField(label=_("评论 Comment"), widget=forms.Textarea,

But it failed when I runserver again, it says

SyntaxError: Non-ASCII character '\xe5' in file /usr/lib/python2.7/site-packages/django/contrib/comments/ on line 98, but no encoding declared; see for details

So I went to and Add "# -- coding: utf-8 --" in the head of file. To be joy, I can run the server. But when I went to the comment Page, the comment form disappeared!

Can anybody tell me what's going on? And how to repair it ?


Django's comments app is already translated to Chinese, you don't need to do that yourself.

You will just need to enable internationalization in your django configuration:

USE_I18N = True

  ('zh_CN', 'Chinese'),

You can roll back all the changes you made to the django/contrib/comments/ file.