#1193 closed enhancement (invalid)
Write {% load i18n %} only once
| Reported by: | 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 , 20 years ago
comment:2 by , 20 years ago
| Component: | Internationalization → Template system |
|---|---|
| Owner: | changed from to |
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 , 20 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
This is a feature of the template system.
comment:4 by , 13 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?
follow-up: 6 comment:5 by , 13 years ago
for reference (eg. anonymous question) this is how to always load a tag
comment:6 by , 13 years ago
Replying to Stefano Crosta <stefano@…>:
for reference (eg. anonymous question) this is how to always load a tag
I
It fails on add_to_builtins('django.contrib.staticfiles.templatetags.staticfiles')
ImproperlyConfigured: The SECRET_KEY setting must not be empty.
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.