Python Django国际化问题
我第一次使用Django国际化。我已经看了这些文件,也做了同样的事情,但没有结果 我的文件夹结构如下Python Django国际化问题,python,django,internationalization,Python,Django,Internationalization,我第一次使用Django国际化。我已经看了这些文件,也做了同样的事情,但没有结果 我的文件夹结构如下 mysite manage.py main __init__.py views.py models.py tests.py mysite __init__.py settings.py views.py urls.py wsgi.py templates
mysite
manage.py
main
__init__.py
views.py
models.py
tests.py
mysite
__init__.py
settings.py
views.py
urls.py
wsgi.py
templates
base.html
locale
en
LC_MESSAGES
django.mo
django.po
fr
LC_MESSAGES
django.mo
django.po
My settings.py类似于:
LANGUAGES = (
('en', 'English'),
('fr', 'French'),
)
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + \
('django.core.context_processors.i18n',)
LOCALE_PATHS = (
'D:\mysite\locale'
)
USE_I18N = True
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
)
from django.utils.translation import ugettext as _
from django.http import HttpResponse
from django.template import RequestContext, loader
def home(request):
template = loader.get_template('base.html')
context = RequestContext(request, {
'latest_question_list': '',
})
return HttpResponse(template.render(context))
{% load i18n %}
{% trans "Hello World" %}
My views.py类似于:
LANGUAGES = (
('en', 'English'),
('fr', 'French'),
)
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + \
('django.core.context_processors.i18n',)
LOCALE_PATHS = (
'D:\mysite\locale'
)
USE_I18N = True
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
)
from django.utils.translation import ugettext as _
from django.http import HttpResponse
from django.template import RequestContext, loader
def home(request):
template = loader.get_template('base.html')
context = RequestContext(request, {
'latest_question_list': '',
})
return HttpResponse(template.render(context))
{% load i18n %}
{% trans "Hello World" %}
我的模板/base.html如下所示:
LANGUAGES = (
('en', 'English'),
('fr', 'French'),
)
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + \
('django.core.context_processors.i18n',)
LOCALE_PATHS = (
'D:\mysite\locale'
)
USE_I18N = True
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
)
from django.utils.translation import ugettext as _
from django.http import HttpResponse
from django.template import RequestContext, loader
def home(request):
template = loader.get_template('base.html')
context = RequestContext(request, {
'latest_question_list': '',
})
return HttpResponse(template.render(context))
{% load i18n %}
{% trans "Hello World" %}
在django.po中locale
下的fr
文件夹中,我添加了
#: .\django\conf\global_settings.py:74
msgid "French"
msgstr "Bonjour tout le monde"
我尝试从工具中更改firefox内容,尝试添加法语并重新加载页面,但没有成功。谁能帮我一下我犯了什么错误。提前感谢即使我很久以前也遇到过同样的问题。这应该对你有用。更改django.po文件后,需要执行以下操作
使用命令compilemessages生成mo文件
重新启动apache服务
重新启动服务后没有运气。已经使用django-admin.py compilemessages-l
创建了mo文件。设置是否适合国际化?