You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I'm not very familiar with the translation process by pybabel I was confused what to do. Unfortunately, the reference doesn't help you when you want to create translations. You search for a procedure.
What's missing in my humble opinion is how to use this tool. How do I create a translation/message catalog, compile it, and update it? Which steps do I need?
Steps to Reproduce
See the documentation.
Actual Results
There is only the reference documentation. How to work with pybabel is missing.
Expected Results
I'd suggest to describe the use cases of pybabel a bit more. This could be added into the "Working with Message Catalogs" topic, for example.
I see the following use cases:
Prepare your translation environment
What do you need? Which configuration options are required? All the things you need before you start.
Create translations
What does the user needs to execute?
Integrate it into a Jinja template
To some degree, it's mentioned. However, IMHO, what's missing is what functions etc. are needed on the Jinja part.
Update translations
When new strings are available, what steps are needed to update your translations?
I figured it out to some degree and it seems to work. Maybe there is a more efficient way to do it or something is missing. Let me know if this is the case.
Here are the (sub)sections that could be integrated into the existing pybabel documentation. Certainly, you need to adapt some sentences, terms etc.
Prepare your translation environment
Make sure you have pybabel installed. See section XYZ for all requirements.
Create a directory, for example translations/, where all your translations are stored.
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
Make sure you name your Jinja2 templates with the file extension .html.jinja2. You can use another file extension if you want, but add it in the babel.cfg file.
Create translations
In order to make pybabel load your translations you need to provide a MO file. For efficiency reasons, it's a binary format. Follow these steps to create this format:
Make sure you have prepared your translation environment as described in "Prepare your translation environment"
Ensure you have added the {% trans %}...{% endtrans %} block in your Jinja2 templates.
If you do not have this, pybabel produces empty catalogs.
$ pybabel update -d translations -i messages.pot
updating catalog translations/de/LC_MESSAGES/message.po based on docserv.pot
updating catalog translations/es/LC_MESSAGES/message.po based on docserv.pot
Translate the PO file.
Compile PO to MO:
$ pybabel compile -d translations/ -l de
compiling catalog translations/de/LC_MESSAGES/messages.po to translations/de/LC_MESSAGES/messages.mo
Reproducibility
See documentation.
Additional Information
n/a
The text was updated successfully, but these errors were encountered:
It definitely would be good to improve the documentation for first-time users. I'm reading it fresh and have no idea what to do. I think it's been written for people who used gettext previously and now want a simpler experience, rather than for first time translators.
Overview Description
The documentation contains the description of the
pybabel
CLI at https://babel.pocoo.org/en/latest/cmdline.html. It's a reference that describes the command line options.As I'm not very familiar with the translation process by pybabel I was confused what to do. Unfortunately, the reference doesn't help you when you want to create translations. You search for a procedure.
What's missing in my humble opinion is how to use this tool. How do I create a translation/message catalog, compile it, and update it? Which steps do I need?
Steps to Reproduce
See the documentation.
Actual Results
There is only the reference documentation. How to work with
pybabel
is missing.Expected Results
I'd suggest to describe the use cases of
pybabel
a bit more. This could be added into the "Working with Message Catalogs" topic, for example.I see the following use cases:
What do you need? Which configuration options are required? All the things you need before you start.
What does the user needs to execute?
To some degree, it's mentioned. However, IMHO, what's missing is what functions etc. are needed on the Jinja part.
When new strings are available, what steps are needed to update your translations?
I figured it out to some degree and it seems to work. Maybe there is a more efficient way to do it or something is missing. Let me know if this is the case.
Here are the (sub)sections that could be integrated into the existing pybabel documentation. Certainly, you need to adapt some sentences, terms etc.
Prepare your translation environment
Make sure you have pybabel installed. See section XYZ for all requirements.
Create a directory, for example
translations/
, where all your translations are stored.Create a
babel.cfg
file with the following content:Make sure you name your Jinja2 templates with the file extension
.html.jinja2
. You can use another file extension if you want, but add it in thebabel.cfg
file.Create translations
In order to make pybabel load your translations you need to provide a MO file. For efficiency reasons, it's a binary format. Follow these steps to create this format:
Make sure you have prepared your translation environment as described in "Prepare your translation environment"
Ensure you have added the
{% trans %}...{% endtrans %}
block in your Jinja2 templates.If you do not have this, pybabel produces empty catalogs.
Extract all translatable strings with:
This command creates a
messages.pot
file in your current directory.Create the translation file with:
This command creates a file
messages.po
in the directorytranslations/de/LC_MESSAGES/
.Translate the PO file
Use KDE's
lokalize
or any other tool that can read the PO format.Repeat step 4 + 5 for other languages.
Compile PO to MO.
Update translations
If you add or remove translatable strings from your Jinja2 templates, you need to update your translations as well.
Extract all translatable strings with:
Update the catalog translations:
Translate the PO file.
Compile PO to MO:
Reproducibility
See documentation.
Additional Information
n/a
The text was updated successfully, but these errors were encountered: