Opened 18 years ago

Closed 18 years ago

Last modified 8 years ago

#1193 closed enhancement (invalid)

Write {% load i18n %} only once

Reported by: inerte@… Owned by: Adrian Holovaty
Component: Template system Version: dev
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...

Change History (7)

comment:1 by jim-django@…, 18 years ago

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 by hugo, 18 years ago

Component: InternationalizationTemplate system
Owner: changed from hugo to Adrian Holovaty

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 by Adrian Holovaty, 18 years ago

Resolution: invalid
Status: newclosed

This is a feature of the template system.

comment:4 by anonymous, 11 years ago

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 by Stefano Crosta <stefano@…>, 11 years ago

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

in reply to:  5 comment:6 by anonymous, 11 years ago

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.

comment:7 by Ciro Santilli 六四事件 法轮功 包卓轩, 8 years ago

+1

Note: See TracTickets for help on using tickets.
Back to Top