JinjaUtilGUI¶
JinjaUtilGUI
| 项目信息 | |
|---|---|
| 仓库 | https://github.com/Maicarons/JinjaUtilGUI |
| 主要语言 | Python |
| Stars | 0 |
| 类型 | 原创项目 |
| 许可证 | MPL-2.0 |
| 最近更新 | 2026-02-05 |
Jinja Template GUI Tool¶
A graphical user interface tool built with tkinter for processing Jinja2 template files.
🌍 Internationalization Support¶
This tool now supports internationalization in 7 languages: - Simplified Chinese (Default) - English - Japanese - Korean - German - French - Italian
Switch languages through the "Language" option in the top menu bar.
Features¶
- 🖥️ Intuitive graphical interface operation
- 📁 Support for selecting Jinja2 template files (.j2, .tpl, .tmpl formats)
- 📝 Dual-mode data input (form input and JSON input)
- 🔍 Automatic template variable detection
- 👁️ Real-time preview of generated results
- 💾 Result saving functionality
- 🔄 Template hot reloading
Installation¶
Install the required dependencies:
pip install -r requirements.txt
Usage¶
Run the main program:
python main.py
Interface Overview¶
1. Template Selection Area¶
- Select File: Browse and select Jinja2 template files
- Reload: Reload the current template file
- Display the currently selected file name
2. Data Input Area¶
Two data input methods are provided:
Form Input Tab: - Automatically detects variables in the template - Generates input fields for each variable - Supports automatic type conversion (numbers, booleans, lists, etc.)
JSON Input Tab: - Direct input of JSON formatted data - Suitable for complex data structures - Real-time syntax validation
3. Result Display Area¶
- Real-time display of generated text results
- Scrollable view for long texts
- Syntax-highlighted friendly display
4. Action Buttons¶
- Generate Text: Render template based on input data
- Save Result: Save generated results to file
- Clear All: Clear all inputs and results
Template Syntax Support¶
Supports standard Jinja2 syntax and special functions:
Variable Substitution¶
Hello {{ name }}!
Your age is {{ age }} years.
Conditional Statements¶
{% if age >= 18 %}
Adult
{% else %}
Minor
{% endif %}
Loop Statements¶
<ul>
{% for item in items %}
<li>{{ item }}</li>
{% endfor %}
</ul>
Special Function Support¶
{# Exception handling function #}
{{ raise_exception("Error message") }}
{# String processing functions #}
{{ text | trim }}
Complex Template Examples¶
The tool supports complex chat templates like chat_template.jinja, including:
- Multi-language support
- Role alternation validation
- Content type handling (text/image)
- Strict format validation
Example Templates¶
The project includes two example templates:
test_template.html.j2- HTML resume templateresume_template.txt.j2- Text resume template
Configuration File¶
The program automatically generates a config.json configuration file that stores:
- Recently used templates
- Window size settings
- Font size
- Last used variable values
Error Handling¶
- Template syntax error notifications
- JSON format validation
- File read/write exception handling
- User-friendly error messages
Development Information¶
Project Structure¶
jinjautil/
├── main.py # Main program entry point
├── template_processor.py # Core template processing logic
├── i18n.py # Internationalization manager
├── requirements.txt # Dependency list
├── README.md # English documentation
├── README_zh.md # Chinese documentation
├── config.json # Unified configuration file
├── locales/ # Translation files directory
│ ├── zh_CN/ # Chinese translations
│ ├── en_US/ # English translations
│ └── ... # Other language translations
└── example/ # Example template files
├── test_template.html.j2
└── resume_template.txt.j2
Core Components¶
- Main Application (
main.py) - Tkinter-based GUI implementation
- Menu system with language switching
- File selection and template loading
- Data input handling (both form and JSON)
-
Result display and export functionality
-
Template Processor (
template_processor.py) - Jinja2 environment configuration
- Variable extraction from templates
- Template rendering with data merging
-
Custom function and filter support
-
Internationalization (
i18n.py) - Multi-language support management
- gettext-based translation system
- Language switching with runtime updates
- Configuration persistence
Dependencies¶
- Jinja2 (>=3.1.0): Template engine
- Babel (>=2.12.0): Internationalization utilities
- Python Standard Library: tkinter, json, os, pathlib
Adding New Languages¶
- Create new language directory:
locales/{language_code}/LC_MESSAGES/ - Copy existing
.pofile and translate messages - Compile translations:
pybabel compile -d locales - Add language to
SUPPORTED_LANGUAGESini18n.py
Contributing¶
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Support¶
For issues, feature requests, or questions: - Open an issue on GitHub - Check existing documentation - Review example templates for usage patterns