Revision history [back]
Hi, well. I still couldn't translate it, but I think I'm near :)
What I did was copy the language function from Django 1.5 version to a new file in askbot/templatetags directory (askbot 0.7.48).
But when I try to import the template, it fails with this message:
TemplateSyntaxError: Encountered unknown tag 'language'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.
This is what I have: In instant_notification.py:
{% block subscription %}
{% load i18n_customized %}
{% language "es" %}
Hello World
{% endlanguage %}
{%endblock%}
And I've got a i18n_customized.py with the function:
@register.tag
def language(parser, token):
"""
This will enable the given language just for this block.
Usage::
{% language "de" %}
This is {{ bar }} and {{ boo }}.
{% endlanguage %}
"""
... (the same code as in i18n.py) ...
return LanguageNode(nodelist, language)
Also, I tried with
register.tag('language', language)
I debugged the code and the function is registered in the system.
For what I see, is something related to Jinja, but I don't know how to resolve it.
Any help is welcome
Traceback:
In [1]: from django.template.loader import get_template
In [2]: get_template('email/instant_notification.html')
TemplateSyntaxError Traceback (most recent call last)
<ipython-input-2-20bfe4850f9a> in <module>()
----> 1 get_template('email/instant_notification.html')
Cut all stack for get_template called
...askbot-src/askbot/skins/loaders.pyc in get_askbot_template(template, request)
112 if hasattr(request,'LANGUAGE_CODE'):
113 skin.set_language(request.LANGUAGE_CODE)
--> 114 return skin.get_template(template)
115
116 def render_into_skin_as_string(template, data, request):
...local/lib/python2.7/site-packages/jinja2/environment.pyc in get_template(self, name, parent, globals)
789 if parent is not None:
790 name = self.join_path(name, parent)
--> 791 return self._load_template(name, self.make_globals(globals))
792
793 @internalcode
...local/lib/python2.7/site-packages/jinja2/environment.pyc in _load_template(self, name, globals)
763 template.is_up_to_date):
764 return template
--> 765 template = self.loader.load(self, name, globals)
766 if self.cache is not None:
767 self.cache[name] = template
...local/lib/python2.7/site-packages/jinja2/loaders.pyc in load(self, environment, name, globals)
393 for loader in self.loaders:
394 try:
--> 395 return loader.load(environment, name, globals)
396 except TemplateNotFound:
397 pass
...local/lib/python2.7/site-packages/jinja2/loaders.pyc in load(self, environment, name, globals)
123 # date) etc. we compile the template
124 if code is None:
--> 125 code = environment.compile(source, name, filename)
126
127 # if the bytecode cache is available and the bucket doesn't
...local/lib/python2.7/site-packages/jinja2/environment.pyc in compile(self, source, name, filename, raw, defer_init)
552 except TemplateSyntaxError:
553 exc_info = sys.exc_info()
--> 554 self.handle_exception(exc_info, source_hint=source)
555
556 def compile_expression(self, source, undefined_to_none=True):
...local/lib/python2.7/site-packages/jinja2/environment.pyc in handle_exception(self, exc_info, rendered, source_hint)
740 self.exception_handler(traceback)
741 exc_type, exc_value, tb = traceback.standard_exc_info
--> 742 reraise(exc_type, exc_value, tb)
743
744 def join_path(self, template, parent):
/home/mgieco/Desarrollos/askbot-src/askbot/templates/email/instant_notification.html in template()
10 {% load i18n_customized %}
11
---> 12 {% language "es" %}
13 Hello World
14 {% endlanguage %}
TemplateSyntaxError: Encountered unknown tag 'language'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.