- 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
24 lines
770 B
Python
24 lines
770 B
Python
#!/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()
|