不能创建django.po

时间:2014-01-29 17:20:47

标签: python django python-2.7 django-i18n

我是django网络应用的新手,

我的项目结构如下: X    - &X的催化剂    - > settings.py

在settings.py中的

我有以下条目:

from django.utils.translation import ugettext_lazy as _
LOCALE_PATHS = ( 
join (BASE_DIR, 'locale'), 
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.locale.LocaleMiddleware',
)

LANGUAGE_CODE = 'en-us'
LANGUAGES = (
    ('en', _('English')),
    #('en-us', ugettext('English US')),
    ('es', _('Spanish')),
    ('en-Gb', _('English UK')),
)

USE_I18N = True

USE_L10N = True

USE_TZ = True

我在MAC OSX 10.7.5上安装了get文本

在我的模板中:

{% load i18n %}
{% trans "Login To UI Mirror" %}

使用以下命令

django-admin.py makemessages -a

似乎能够生成django.po

缺少它

模板中定义的消息ID。

这是它的内容:

#: settings.py:156
msgid "English"
msgstr ""

#: settings.py:158
msgid "Spanish"
msgstr ""

#: settings.py:159
msgid "English UK"
msgstr ""

任何帮助将不胜感激。

由于

模板代码:

_base.html:

{% load compress %}
{% load i18n %}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        {# Mobile meta tag #}
        <meta name="HandheldFriendly" content="True">
        <meta name="MobileOptimized" content="320">
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
        <meta http-equiv="cleartype" content="on">
        {# Favicons #}
        <link rel="icon" href="{{static}}images/uimirror.ico" type="image/x-icon">
        {% block title %}
            {% include "core/_title.html" with location='lgn_reg' %}
        {% endblock title %}

        {# Tile icon for Win8 (144x144 + tile color) #}
        {% block css_media %}
            {% include "core/_media.html" with location='lgn_reg' %}
        {% endblock css_media %}
    </head>

    <body>
        {% block content %}

        {% endblock content %}

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
        {% block script_media %}
            {% include "core/_script_media.html" with location='lgn' %}
        {% endblock script_media %}

    </body>
</html>

第一次延伸:

login_register.html

{% extends 'core/_base.html' %}

{% block css_media %}
    {% include "core/_media.html" with location=location %}
{% endblock css_media %}

{% block content %}
    <div class="uimmaincontainer" id="uimmaincontainer">
    {% include "core/login_register/_login_register_theme.html" with location=location %}
    {% include "core/login_register/_login.html" with location=location%}
    {% include "core/login_register/_register.html" with location=location%}
    </div>
{% endblock content %}

Trans block:

_login_register_theme.html

{% load i18n %}
<div class="pt15 {% if location == 'lgn' %} active {% else %} hidden {% endif %}" id="_ui_lgn_them">
    <h4 aria-hidden="true" class="">
        <img width="15" height="15" alt=""
            src="#"
            class="uiHeaderImage img">{% trans "Login To UI Mirror" %}
    </h4>
    <div class="clearfix">
        <div class="mb5 uiHeaderSubTitle f-left fsm tc-3">Enter to the most existing virtual world.</div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

我认为您的模板目录结构存在问题。 Django template loader正在您的应用中寻找名为“模板”的目录。

您的模板位于core/login_register/下,因此django无法找到它们。

您可以对模板使用以下结构:

└── yourapp
    └── templates
        └── yourapp 
            ├── base.html
            └── index.html

这样,django会找到你的模板,你甚至可以在其他应用程序中覆盖这些模板:

└── yourapp
    └── templates
        └── yourapp 
            ├── base.html
            └── index.html
└── anotherapp
    └── templates
        └── yourapp 
            ├── base.html # it will override the template yourapp/templates/yourapp/base.html

这是common structure for django projects