Code

Opened 8 years ago

Closed 8 years ago

Last modified 12 months ago

#1193 closed enhancement (invalid)

Write {% load i18n %} only once

Reported by: inerte@… Owned by: adrian
Component: Template system Version: master
Severity: minor Keywords: i18n, trans
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you use {% trans "string" %}, {% load i18n %} must exists on the same template file.

What I want to do is to put {% load i18n %} only once on my "base" template and use {% trans "string" %} on every "children" template, since translations are usually necessary for the whole website.

Error condition:

base.html

{% load i18n %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
etc...

index.html

{% extends "base" %}
{% trans "hellow world" %}

It shows a Invalid block tag: 'trans' error...

Attachments (0)

Change History (6)

comment:1 Changed 8 years ago by jim-django@…

My understanding is that this is a feature, not a bug. The template system only provides the tags loaded in each template file itself so that templates can be reused without having to guess at what their environment expectations are.

A fix for the problem of having to put {% load i18n %} in every template might be to add an app-specific automatically loaded template setting, so each app author can decide what the base namespace for their templates is. This would require adding an app-specific configuration system, and somehow letting the template module know what the 'current app' is.

comment:2 Changed 8 years ago by hugo

  • Component changed from Internationalization to Template system
  • Owner changed from hugo to adrian

As jim says, this is a feature of the template system: you need to load the taglibs to use in every template that uses the taglib. The idea of a setting to define "default taglibs" on the other hand is something that might be useful - so I reassign it to the template system, so Adrian can comment.

comment:3 Changed 8 years ago by adrian

  • Resolution set to invalid
  • Status changed from new to closed

This is a feature of the template system.

comment:4 Changed 15 months ago by anonymous

  • Easy pickings unset
  • UI/UX unset

I don't understand, so how would I add {% load i18n %} to the default taglibs?

What is the feature of the template system called?

comment:5 follow-up: Changed 12 months ago by Stefano Crosta <stefano@…>

for reference (eg. anonymous question) this is how to always load a tag

http://stackoverflow.com/questions/1184983/load-a-django-template-tag-library-for-all-views-by-default

comment:6 in reply to: ↑ 5 Changed 12 months ago by anonymous

Replying to Stefano Crosta <stefano@…>:

for reference (eg. anonymous question) this is how to always load a tag

http://stackoverflow.com/questions/1184983/load-a-django-template-tag-library-for-all-views-by-default

I
It fails on add_to_builtins('django.contrib.staticfiles.templatetags.staticfiles')

ImproperlyConfigured: The SECRET_KEY setting must not be empty.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.