Thursday, October 29, 2015

Translation is not working for Template even though po and mo files are created

Hi,

I'm learning Django Translation using django-swingtime with Django 1.7.9 installed.
I followed the official docs and embedded my string to translate with <title>{% trans "String to translate" %}</title> in my Template and managed to create both the po and mo files successfully.
But, the page is still shown up in English.
Note: the translation works just fine for my models.

Partly of the template I was using can be found from below:
{% extends "base.html" %}
{% load url from future %}
{% load i18n %}
{% block title %}Event Occurrence{% endblock %}
{% block main_content %}
     
<h3>{% trans "Swingtime Event Occurrence" %}</h3>
     
<h4>
         
<a href="{{ occurrence.event.get_absolute_url }}">{{ occurrence.title }}</a>
         
&ndash;
         
{% with occurrence.start_time as st  %}
         
<a href="{% url 'swingtime-daily-view' st.year st.month st.day %}">
           
{{ st|date:"l, F jS P" }}</a>
       
</h4>
        {% endwith %}
     <dl>
         <dt>{% trans "Event type:" %}</
dt>
         
<dd>{{ occurrence.event.event_type }}</dd>

The subroutine to render my Template is:
#-------------------------------------------------------------------------------
def occurrence_view(
    request
,
    event_pk
,
    pk
,
   
template='swingtime/occurrence_detail.html',
    form_class
=forms.SingleOccurrenceForm
):
   
'''
    View a specific occurrence and optionally handle any updates.
   
    Context parameters:
   
    ``occurrence``
        the occurrence object keyed by ``pk``


    ``form``
        a form object for updating the occurrence
    '''

 
    occurrence
= get_object_or_404(Occurrence, pk=pk, event__pk=event_pk)
   
if request.method == 'POST':
        form
= form_class(request.POST, instance=occurrence)
       
if form.is_valid():
            form
.save()
           
return http.HttpResponseRedirect(request.path)
   
else:  
        form
= form_class(instance=occurrence)
       
   
return render(request, template, {'occurrence': occurrence, 'form': form})

And the url configuration associated with the Template reads:
    url(
        r
'^events/(\d+)/(\d+)/$',
        views
.occurrence_view,
        name
='swingtime-occurrence'
   
),

Could some one help me solve this problem?
Thanks very much

Br
Sean

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a45afc10-97ad-4574-b541-14ff67e892cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment