如何将Django的评论表单的默认标签名称改为中文?

时间:2021-08-26 07:44:29

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

我正在使用Django的内置评论应用程序,但是我遇到了一个问题。

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:

注释表单的默认标签是英语(例如:“姓名”、“电子邮件地址”),但我想把它们换成中文。于是我去了站点包/django/悔过书/评论/表单。py,修改如下:

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!

于是我去了http://www.python.org/peps/pep-0263.html,在表单的头部添加了#——编码:utf-8——。py文件。为了好玩,我可以运行服务器。但是当我去评论页面时,评论表单就消失了!

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

谁能告诉我是怎么回事吗?怎么修理呢?

1 个解决方案

#1


2  

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

Django的评论应用已经被翻译成中文了,你不需要自己做。

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

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

USE_I18N = True

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

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

您可以回滚对django/悔过书/注释/表单所做的所有更改。py文件。

#1


2  

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

Django的评论应用已经被翻译成中文了,你不需要自己做。

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

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

USE_I18N = True

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

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

您可以回滚对django/悔过书/注释/表单所做的所有更改。py文件。