jinja2.exceptions.UndefinedError: 'gettext' is undefined
See original GitHub issueI’m using Jinja2 2.7.3 inderectly through pelican and I get this error with templates using {% trans% } directive. So be sure it’s not related to pelican, i’ve created this small test file (https://gist.github.com/njouanin/36292368ad15f9b87ba0). When I run it with python interpreter (3.4.1) I get the following exception :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/nico/Brassage/Beerfactory/env-site/lib/python3.4/site-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/Users/nico/Brassage/Beerfactory/env-site/lib/python3.4/site-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/nico/Brassage/Beerfactory/env-site/lib/python3.4/site-packages/jinja2/_compat.py", line 36, in reraise
raise value.with_traceback(tb)
File "theme/templates/base.html", line 50, in <module>
{% block header_left_section %}
File "theme/templates/base.html", line 60, in <module>
<h2 id="site-description">{{ gettext('Brasser libre !') }}</h2><!-- #site-description -->
jinja2.exceptions.UndefinedError: 'gettext' is undefined
I’ve googled this issue which appear to be related to gettext library which is missing. Here importing gettext module in python works fine, so I guess it is installed. Here is my environnement : MacOs 10.9 Python 3.4.1 Jinja2 : 2.7.3
Issue Analytics
- State:
- Created 9 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Django+Jinja2+i18n - 'gettext' is undefined - Stack Overflow
Here is my solution after many tries. The 'jinja2.ext.i18n' doesn't install gettext automatically, so you need to add it first to the ...
Read more >Jinja2 i18n problem: UndefinedError: 'gettext' is undefined
Hi there, I tried a very simple test to check the Jinja2 i18n, here is the code (it is pretty much the same...
Read more >jinja2.exceptions.UndefinedError: 'gettext' is undefined-django
Here is my solution after many tries. The 'jinja2.ext.i18n' doesn't install gettext automatically, so you need to add it first to the Environment...
Read more >2. i18n Extension — Jinja2 API - GitHub Pages
If the i18n extension is enabled Jinja2 provides a trans statement that marks the wrapped string as translatable and calls gettext . After...
Read more >jupyterlab/jupyterlab - Gitter
endtrans %}<br> jinja2.exceptions.UndefinedError: 'gettext' is undefined. Steven Silvester. @blink1073. @timkpaine, I'm not familiar how to use the trans ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m going to close this issue. This happens if the i18n extension is installed but no gettext function is provided. This is a configuration problem of whatever integrated Jinja into a project.
You (or the library that’s configuring Jinja for you) need to install the gettext functions after enabling the i18n extension. This is shown in the docs https://jinja.palletsprojects.com/en/3.0.x/extensions/#i18n-extension