Skip to content

๐Ÿงฉ jinja-i18n-tools

Automated i18n tool for Jinja2-based projects using Babel and Google Translate.

๐Ÿ“ฆ Features

  • ๐Ÿ” Extract translatable strings from your Jinja2 templates.
  • ๐ŸŒ Initialize .po files for multiple languages.
  • ๐Ÿค– Auto-translate using Google Translate via deep_translator.
  • ๐Ÿ› ๏ธ Compile .po files into .mo.
  • ๐Ÿงน Automatically cleans up temporary files like messages.pot and babel.cfg.

โš™๏ธ Installation

pip install jinja-i18n-tools

๐Ÿš€ Usage

Activate your virtual environment, then run:

jinja-i18n full

This will: 1. Copy babel.cfg to your project root. 2. Extract translatable strings from your templates. 3. Initialize translation files for each language. 4. Auto-translate all strings. 5. Compile .po files into .mo. 6. Clean up temporary files.


๐Ÿ› ๏ธ CLI Commands

jinja-i18n extract
jinja-i18n init
jinja-i18n translate --lang ar
jinja-i18n translate-all
jinja-i18n compile
jinja-i18n full --lang all --force

๐ŸŒ Languages

By default, the following languages are supported:

  • ar โ€“ Arabic
  • de โ€“ German

You can customize this in the source by editing the LANGUAGES list.


๐Ÿ“ Project Structure

Your Jinja2 templates and Python files must be located where your babel.cfg expects them. Here's a recommended configuration:

[python: **.py]
[jinja2: templates/**.html]
[jinja2: templates/**.j2] 
extensions=jinja2.ext.i18n

This configuration instructs pybabel to:

  • Extract translation strings from all Python files recursively.
  • Extract translatable content from all .html templates under the templates/ folder.
  • Enable the jinja2.ext.i18n extension to support {% trans %} blocks.

Make sure this file (babel.cfg) is located in your project root temporarily, or is copied automatically by the tool before running pybabel extract.


๐Ÿงผ Cleanup

Temporary files like babel.cfg and messages.pot are deleted automatically after the process finishes.


๐Ÿ“œ License

This project is licensed under the MIT License.
You are free to use, modify, and distribute it with attribution.
Feel free to explore and build upon it!


๐Ÿ‘จโ€๐Ÿ’ป About the Author

๐ŸŽฏ Tamer OnLine โ€“ Developer & Architect
A dedicated software engineer and educator with a focus on building multilingual, modular, and open-source applications using Python, Flask, and PostgreSQL.

๐Ÿ”น Founder of Flask University โ€“ an initiative to create real-world, open-source Flask projects
๐Ÿ”น Creator of @TamerOnPi โ€“ a YouTube channel sharing tech, tutorials, and Pi Network insights
๐Ÿ”น Passionate about helping developers learn by building, one milestone at a time

Connect or contribute:

GitHub
LinkedIn
YouTube


๐Ÿ’ก Got feedback or want to collaborate?
Open an issue, fork the repo, or just say hi on LinkedIn!