mezzanine添加中文支持

安装完mezzanine你会发现其界面是英文的,而且后台没有设置语言的地方。百度了一圈发现只有两篇介绍mezzanine中文的文章,按照文章里的方法,却不能正常运行,折腾了两天之后,终于实现了中文支持,特此给大家整理了一下。

1.给系统安装中文包

查看当前系统语言

echo $LANG

查看安装的语言包

locale

如果没有中文语言,需要安装中文语言包。

yum groupinstall chinese-support

修改系统默认语言

vi /etc/sysconfig/i18n/

LANG="zh_CN.utf8"

设置完成后  重启  即完成了语言包安装

2.修改配置文件  settings.py   修改下面代码中加粗的地方

USE_MODELTRANSLATION = True
########################
# MAIN DJANGO SETTINGS #
######################### Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'UTC'
# If you set this to True, Django will use timezone-aware datetimes.
USE_TZ = True
USE_L10N=True
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en"
# Supported languages
LANGUAGES = ( 
 ('en', _('English')),
 ('zh-cn', _(u'中文')), 
)
# A boolean that turns on/off debug mode. When set to ``True``, stack traces
# are displayed for error pages. Should always be set to ``False`` in
# production. Best set to ``True`` in local_settings.py
DEBUG = True
# Whether a user's session cookie expires when the Web browser is closed.
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

这时候你重启应用,会发现运行错误

这是因为settings.py中含有中文字符,需要在文件开始的地方加入以下代码 用来指定字符编码

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

这时候你再运行应用,你会发现前后台都已经变成中文的了。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注