Django语言环境/翻译未显示

时间:2012-12-08 20:05:33

标签: python django translation gettext

在典型的Django开发风格中,为了形成一个完整的图片,我正在使用

的组合

我已经建立了一个新的Django 1.4网站,其中包含一个工作“主页”的应用程序和模板,其中包含以下内容:

{% load i18n %}
{% trans "hello" %}

我的settings.py文件遵循第二个教程。这是我的中间件类:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

我的views.py文件如下所示:

from django.template import Context, loader, RequestContext
from django.http import HttpResponse
from django.shortcuts import render_to_response

def index(request):
    c = Context({})
    return render_to_response('home/index.html', c, context_instance=RequestContext(request))

真正令人困惑的是如何编辑我的语言环境文件夹中的django.py文件。教程说“编辑它们”,Django文档没有提及它们,SO问题说要摆脱#, fuzzy行。

这是该文件的样子(在顶部)

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid "hello"
msgstr "Bonjour le Monde"
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-12-08 19:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

1 个答案:

答案 0 :(得分:1)

在makemessages命令之后你应该在django.po:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-12-08 19:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: templates/home/index.html:2
msgid "hello"
msgstr ""

您在哪里存储模板和翻译?在应用程序或项目目录中?