Question

I am new to django web app,

my project structure looks like: x ->x ->settings.py

in settings.py I have following entry:

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

I have installed get text on my MAC OSX 10.7.5

in my template:

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

Using the below command

django-admin.py makemessages -a

seems its able to generate django.po

but it is missing with

message id defined in template.

here is what it has:

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

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

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

Any help will be appreciated.

Thanks

Template Codes:

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

1st extend:

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>
Was it helpful?

Solution

I think there is a problem with your template directory structure. Django template loader is looking for a directory called "templates" within your app.

Your templates are located under core/login_register/, so django can't find them.

You can use the following structure for your templates :

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

This way, django will find your templates, and you'll even be able to override these templates in other apps :

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

It's a common structure for django projects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top