2

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 site-packages/django/contrib/comments/forms.py 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,
                               max_length=COMMENT_MAX_LENGTH)

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/forms.py on line 98, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

So I went to http://www.python.org/peps/pep-0263.html and Add "# -- coding: utf-8 --" in the head of forms.py 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 ?

4

1 回答 1

2

Django 的comments应用程序已经翻译成中文了,你不需要自己做。

您只需要在 django 配置中启用国际化:

USE_I18N = True

LANGUAGES = (
  ('zh_CN', 'Chinese'),
)

您可以回滚对django/contrib/comments/forms.py文件所做的所有更改。

于 2013-01-04T00:04:37.423 回答