Files
TimeTracker/scripts/extract_translations.py
T
Dries Peeters 5ace391bd9 feat(i18n): Add comprehensive translation support across all templates
- Replace hardcoded English strings with translation function calls in 36 template files
- Update translation files for all supported languages (ar, de, es, fi, fr, he, it, nb, nl, no)
- Add over 55,000 new translation entries across all language files
- Update extract_translations.py to use 'python -m babel.messages.frontend' instead of pybabel
- Improve internationalization coverage for UI elements including:
  * Skip to content links
  * Sidebar toggle buttons
  * Command palette placeholders
  * Admin dashboard elements
  * Form labels and buttons
  * Report templates
  * Payment and invoice views

This commit significantly improves the application's multilingual support
by making previously hardcoded strings translatable.
2025-11-18 11:35:57 +01:00

36 lines
1.1 KiB
Python

import os
import subprocess
def run(cmd: list[str]) -> int:
print("$", " ".join(cmd))
# Use python -m babel instead of pybabel directly
if cmd[0] == 'pybabel':
cmd = ['python', '-m', 'babel.messages.frontend'] + cmd[1:]
return subprocess.call(cmd)
def main():
# Requires Flask-Babel/Babel installed
os.makedirs('translations', exist_ok=True)
# Extract messages
run(['pybabel', 'extract', '-F', 'babel.cfg', '-o', 'messages.pot', '.'])
# Initialize languages if not already
languages = ['en', 'nl', 'de', 'fr', 'it', 'fi', 'es', 'ar', 'he', 'nb']
for lang in languages:
po_dir = os.path.join('translations', lang, 'LC_MESSAGES')
po_path = os.path.join(po_dir, 'messages.po')
if not os.path.exists(po_path):
run(['pybabel', 'init', '-i', 'messages.pot', '-d', 'translations', '-l', lang])
# Update catalogs
run(['pybabel', 'update', '-i', 'messages.pot', '-d', 'translations'])
# Compile
run(['pybabel', 'compile', '-d', 'translations'])
if __name__ == '__main__':
main()