Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7037065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:29:56+00:00 2026-05-28T01:29:56+00:00

I try to enable the trans tag and I’ve made a test template i18n.html:

  • 0

I try to enable the trans tag and I’ve made a test template i18n.html:

{% trans %}For sale{% endtrans %}--{{message}}--{{decimal_format}}
Here is my python code according to the manpages:

from webapp2_extras import i18n as multilingua
import jinja2
from webapp2_extras.i18n import lazy_gettext as gettext
from webapp2_extras.i18n import lazy_gettext as _
from jinja2 import Environment, FileSystemLoader
jinja_environment =  jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
                      extensions=['jinja2.ext.i18n'])

# The code below seems wrong since it is django but it was the only way I could make the page load

jinja_environment.install_gettext_translations(django.utils.translation)

class HelloWorldHandler(webapp2.RequestHandler):
    def get(self):
        # Set the requested locale.
        locale = self.request.GET.get('locale', 'pt')
        multilingua.get_i18n().set_locale(locale)
        message = multilingua.gettext('For sale')
        #django.utils.translation.activate('pt')
        template = jinja_environment.get_template('templates/i18n.html')
    decimal_format = multilingua.I18n(self.request).format_decimal(1000)
        self.response.out.write(template.render(message=message, decimal_format=decimal_format))

I could not make it work without django and therefore I ask how to lose the django translation and staying with webapp2.i18n + jinja instead.

There was also a discussion in a thread where I’m not the only one saying that documentation is somewhat incomplete or hard to find. Could you please answer or comment which is the recommended way of making the trans tag work and why I must include jinja_environment.install_gettext_translations(django.utils.translation)
?

When I try to remove my use of django I also lose the functions of webapp2.i18n. My locale files are both in locale/… and conf/locale.. since the first is the default for webapp2 and the second is the default for django translations, so I could really use some guidelines for best practice here to get rid of the django dependecies and use webapp2 and jinja for rendering my localizations.

If to any help, I did receive an error message when trying to remove django:

    self.response.out.write(template.render(message=message, decimal_format=decimal_format))
  File "/media/Lexar/montao/montaoproject/jinja2/environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "/media/Lexar/montao/montaoproject/templates/i18n.html", line 2, in top-level template code
    {{ _('For sale') }}--{{message}}--{{decimal_format}}
UndefinedError: 'gettext' is undefined

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:29:57+00:00Added an answer on May 28, 2026 at 1:29 am

    Take a look at Jinja2’s i18n Extension documentation. Calling install_gettext_translations basically sets the object through which Jinja2 will call gettext, ngettext, etc, in order to translate strings when it encounters a {% trans %} tag.

    Since those functions are defined on webapp2.i18n (see here), jinja2 will successfully call those functions to retrieve translations, dependent upon your call to set_locale inside of the request. I don’t have the code in front of me, but I’d guess that gettext and company defined in webapp2.i18n are merely proxies to call webapp.i18.get_i18n().gettext, which is the magic that makes all of this work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try enable reCAPTCHA with the tag {{capture}} The expected output is the reCAPTCHA
try { Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.setProperty("mail.transport.protocol", "smtp"); props.setProperty("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.auth",
I am trying to follow the examples from here http://www.haskell.org/cabal/users-guide/#test-suites When I run cabal
I try to use the following technique in order to enable/disable the shadow effect
I try to enable a brwoserback button for my tabs. But the problem is
I logged into my PC with administrator account. When I try to enable the
I try to modify the metabase of IIS6, I've cheched the checkbox to enable
When i try to enable the SSL (editing server.xml to enable port:8443 as HTTPS)
I try to enable foreign keys using HDBC-sqlite3 haskell library. This library uses a
I try to enable msvc memory leak detection with line number like this snippet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.