Overview Description
Thank you for all your efforts in creating and maintaining this project. 👍
Steps to Reproduce
-
Prepare the environment:
$ python3 --version
Python 3.12.1
$ mkdir /tmp/test-pybabel
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install pybabel Jinja2
$ pip install --upgrade pip setuptools
$ pip list
Package Version
---------- ----------
Jinja2 3.1.2
MarkupSafe 2.1.3
pip 23.3.1
pybabel 0.0.0.dev0
setuptools 69.0.2
-
Create a Jinja2 template test.html.jinja2 with the following wrong(!) content:
<html>
<title>{% trans %}Hello World{% trans %}</title>
<body>
<h1>{% trans %}Welcome!{% endtrans %}</h1>
</body>
</html>
-
Create a babel.cfg file with the following content:
[jinja2: **.html.jinja2]
encoding = utf-8
ignore_tags = script,style
include_attrs = alt title summary
keyword = trans
silent = false
-
Extract the translatable strings
$ pybabel extract -F babel.cfg -o test.pot *.html.jinja2
[... very long traceback ...]
File "/home/tux/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jinja2/environment.py", line 611, in parse
self.handle_exception(source=source)
File "/home/tux/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<unknown>", line 2, in template
jinja2.exceptions.TemplateSyntaxError: control structures in translatable sections are not allowed
Actual Results
An (ugly) traceback shown to the user (as presented in step 4).
Expected Results
I'm aware that the silent keyword in babel.cfg leads to this kind of error. However, nevertheless I see an issue when showing the complete traceback to the user:
- It looks like pybabel itself is broken. The traceback underminds its reputability and trust.
- It's scary. Traceback indicates there is something fundamentally wrong, although it's "only" a problem in the Jinja2 template.
- It's too much information. Users overlook the important information.
- It's unfriendly to the user. A user is normally not interested in which package the problem happened. The user is interested why it happened and how to solve it.
All these points make it more difficult for the user to extract the relevant information.
In my opinion, a verbose traceback output should never be shown to the user unless there is really something fundamentally wrong. A syntax problem in a Jinja2 template should not lead to this extensive traceback output and should be condensed to the important information.
In other words, I expected something more user-friendly. 🙂
For example, pybabel should show the relevant information only which is:
- The line number where this problem occurred.
- The problem that was found.
Here is one idea how it could be shown to the user:
$ pybable extract ...
jinja2.exceptions.TemplateSyntaxError (line 2): control structures in translatable sections are not allowed
The real output is subject for another discussion. 😉 But I think you get the idea.
If you want to make it even more useful, suggest a solution to this problem:
$ pybable extract ...
inja2.exceptions.TemplateSyntaxError: line 2 control structures in translatable sections are not allowed
For more information, see <URL>.
The URL could point to a GitHub Wiki in your repo or the actual documentation. The content should show the most common problem and how to solve it. Each content should be consistent to each other and should have the same structure. For example:
Problem
Control structures in translatable sections are not allowed
Cause
Pybabel found ...
Solution
Try the following steps to find the root cause:
1. First step
2. Second step
3. Third step
Reproducibility
See above.
Additional Information
n/a
Overview Description
Thank you for all your efforts in creating and maintaining this project. 👍
Steps to Reproduce
Prepare the environment:
Create a Jinja2 template
test.html.jinja2with the following wrong(!) content:Create a
babel.cfgfile with the following content:Extract the translatable strings
Actual Results
An (ugly) traceback shown to the user (as presented in step 4).
Expected Results
I'm aware that the
silentkeyword inbabel.cfgleads to this kind of error. However, nevertheless I see an issue when showing the complete traceback to the user:All these points make it more difficult for the user to extract the relevant information.
In my opinion, a verbose traceback output should never be shown to the user unless there is really something fundamentally wrong. A syntax problem in a Jinja2 template should not lead to this extensive traceback output and should be condensed to the important information.
In other words, I expected something more user-friendly. 🙂
For example, pybabel should show the relevant information only which is:
Here is one idea how it could be shown to the user:
The real output is subject for another discussion. 😉 But I think you get the idea.
If you want to make it even more useful, suggest a solution to this problem:
The URL could point to a GitHub Wiki in your repo or the actual documentation. The content should show the most common problem and how to solve it. Each content should be consistent to each other and should have the same structure. For example:
Reproducibility
See above.
Additional Information
n/a