1

在典型的 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"
4

1 回答 1

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 ""

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

于 2012-12-08T22:09:45.333 回答