Ask Your Question

Translate email to a specific language

asked 2013-07-22 13:36:40 -0600

matigro gravatar image

Hi, I want to send instant emails translated to Spanish (My application is running in English)

I'm using Django 1.3.1 and I couldn't do it.

I read that in version 1.5 there is a tag language that force translation to a block. But 1.3.1 showed an error with that tag.

Any help is welcome.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-07-24 08:46:20 -0600

matigro gravatar image

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

{% block subscription %}
{% load i18n_customized %}

{% language "es" %}
    Hello World
{% endlanguage %}

And I've got a with the function:

def language(parser, token):
    This will enable the given language just for this block.


    {% language "de" %}
    This is {{ bar }} and {{ boo }}.
    {% endlanguage %}

    ... (the same code as in ...
    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


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)
    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))
    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)
    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)
    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)
    744     def join_path(self, template, parent):

/home/mgieco/Desarrollos/askbot-src/askbot/templates/email/instant_notification.html in template()
     10 {% load i18n_customized %}
---> 12 {% language "es" %}
     13     Hello World
     14 {% endlanguage %}

TemplateSyntaxError ...
edit flag offensive delete link more


Jinja2 actually supports {% trans %}...{% endtrans %} tags, and the language can be set, you'll just need to activate the 'es' locale - see how this step can be done in the django docs/google.

Evgeny gravatar imageEvgeny ( 2013-07-24 08:49:38 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-07-22 13:36:40 -0600

Seen: 291 times

Last updated: Jul 24 '13