feat(i18n): add Spanish localization support with Flask-Babel

- Add Flask-Babel for internationalization
- Configure app for Spanish (default) and English
- Add language switcher in navigation
- Wrap all UI text in templates with gettext()
- Create translation directory structure
- Add complete Spanish translations (58 strings)
- Add English translations (template)
- Compile .po to .mo files
- Add extract_translations.py script for future updates
- Add compile_translations.py script

Spanish is now the default language, with English available via ?lang=en

Translated strings include:
- Navigation (Home, Add Tablet, Add User, etc.)
- User Loans interface (Search, Filter, Status, etc.)
- Table headers (User, Tablet, Serial Number, etc.)
- Buttons (Loan, Return, Search, etc.)
- Messages (No users found, No active loans, etc.)
- All UI text across all templates
This commit is contained in:
ijuanes 2026-06-20 09:58:13 +01:00
parent db7e9591e1
commit 34dd3ca937
13 changed files with 1020 additions and 110 deletions

24
compile_translations.py Normal file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env python3
"""
Compile .po files to .mo files for Flask-Babel
"""
import os
from pathlib import Path
def compile_translations():
translations_dir = Path('translations')
for lang_dir in translations_dir.iterdir():
if lang_dir.is_dir():
lc_messages_dir = lang_dir / 'LC_MESSAGES'
if lc_messages_dir.exists():
for po_file in lc_messages_dir.glob('*.po'):
mo_file = lc_messages_dir / f"{po_file.stem}.mo"
print(f"Compiling {po_file} -> {mo_file}")
# Use msgfmt to compile
os.system(f"msgfmt -o {mo_file} {po_file}")
print("✅ All translations compiled!")
if __name__ == '__main__':
compile_translations()