Hello
I'm new to Jinja2 and what's important to me isn't speed but i18n 
translations and functionality. With python 2.7 Jinja2 and not django seems 
to preferred way to go so I'm rewriting much of my project to use Jinja2 
templates. We already had plenty of translations in .mo and .po files and 
wanted to keep use of those and we also want to make use of django's 
translation package. Can I do this? I found a way to use the django 
translation libraries with jinja2.
Could you review this code and comment if I can use it this way? My SDK is 
google app engine.

import jinja2
from django.utils import translation
from django.utils.translation import gettext, ngettext, ugettext, ungettext, 
get_language, activate
class DjangoTranslator(object):

    def __init__(self):
        self.gettext = gettext
        self.ngettext = ngettext
        self.ugettext = ugettext
        self.ungettext = ungettext
from jinja2 import Environment, FileSystemLoader
class DjangoEnvironment(jinja2.Environment):

    def get_translator(self, context):
        return DjangoTranslator()

jinja_environment = DjangoEnvironment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), 
extensions=['jinja2.ext.i18n'])
jinja_environment.install_gettext_translations(translation)


-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pocoo-libs/-/18Z8B9gNEoIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en.

Reply via email to